malloc.c:2372: sysmalloc: Assertion
malloc.c:2372: sysmalloc: Assertion
/* Dynamic Programming implementation of LCS problem */
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<set>
using namespace std;
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
int** lcs( char *X, char *Y, int m,int n)
{
int **L;
L = new int*[m];
/* Following steps build L[m+1][n+1] in bottom up fashion. Note
that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++)
{
L[i] = new int[n];
for (int j=0; j<=n; j++)
{
if (i == 0 || j == 0)
L[i][j] = 0;
else if (X[i-1] == Y[j-1])
L[i][j] = L[i-1][j-1] + 1;
else
L[i][j] = max(L[i-1][j], L[i][j-1]);
}
}
return L;
}
void printlcs(char *X, char *Y,int m,int n,int *L[],string str)
{
if(n==0 || m==0)
{ cout<<str<<endl;
return ;
}
if(X[m-1]==Y[n-1])
{ str= str + X[m-1];
//cout<<X[m-1];
m--;
n--;
printlcs(X,Y,m,n,L,str);
}else if(L[m-1][n]==L[m][n-1]){
string str1=str;
printlcs(X,Y,m-1,n,L,str);
printlcs(X,Y,m,n-1,L,str1);
}
else if(L[m-1][n]<L[m][n-1])
{
n--;
printlcs(X,Y,m,n,L,str);
}
else
{
m--;
printlcs(X,Y,m,n,L,str);
}
}
/* Driver program to test above function */
int main()
{
char X[] = "afbecd";
char Y[] = "fabced";
int m = strlen(X);
int n = strlen(Y);
int **L;
L=lcs(X, Y,m,n);
string str="";
printlcs(X,Y,m,n,(int **)L,str);
return 0;
}
这是打印所有可能的最长公共子序列的程序。如果我们输入char X[] = "afbecd";char Y[] = "fabced";
,那么它显示以下错误,而对于输入char X[] = "afbec";char Y[] = "fabce"
,它工作正常。solution: malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.
谁能解释一下为什么会出现这种奇怪的行为?由于 在lcs
函数中,您在for
循环中迭代L
数组时超出了数组界限。L
是长度为m
:
int **L;
L = new int*[m];
:
for (int i=0; i<=m; i++)
{
L[i] = new int[n];
访问L[m]
元素时,i == m
。这是未定义行为,因为数组从0
索引,这是对m + 1
元素的访问。
同样的问题出现在下一个循环中访问长度为n
的L[i]
数组中的n + 1
元素时:
for (int j=0; j<=n; j++)
{
// Code skipped
L[i][j] = 0;
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 流行"Debug Assertion Failed"
- Sysmalloc:使用向量的断言错误
- ISALPHA 导致 C++ "Debug Assertion Failed"
- 凯撒密码程序中"Debug Assertion Failed!"问题
- Assertion desc failed at src/libswscale/swscale_internal.h:6
- 如何修复邻接列表中的"Debug Assertion Failed" "vector subscript out of range"
- "Debug assertion failed" 这种有什么问题?它应该按年份对包含电影对象的动态列表进行排序
- 什么是"debug assertion failed"
- Sysmalloc error with opencv
- SQL Server 2016 CLR 存储过程错误:"A system assertion check has failed"
- Visual Studio 2015 OpenCV Assertion 在 cv::imshow windows 中失败 (size.width>0 && size.height>0.cp
- 代码块在尝试编译或创建新文件时出现"An assertion failed!"错误
- 如何修复"static assertion failed: template argument not an integral type"错误?
- 导致"OpenCV(4.0.1) Error : Assertion failed(m.dims <= 2)"的原因
- OpenCV VideoWriter Assertion Failed img.cols == width && img.rows == height*3
- sprintf_s() 失败并显示错误"debug assertion failed"
- 这个错误是什么"test: malloc.c:2388: sysmalloc: Assertion ... failed"
- malloc.c "sYSMALLOC: Assertion"与C++项目一起执行
- malloc.c:2372: sysmalloc: Assertion