malloc.c:2372: sysmalloc: 断言
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];
您在 i == m
时访问 L[m]
元素。这是未定义的行为,作为从 0
索引的数组,这是对 m + 1
元素的访问。
在访问长度为 n
:
的 L[i]
数组中的 n + 1
元素期间,在下一个循环中出现同样的问题
for (int j=0; j<=n; j++)
{
// Code skipped
L[i][j] = 0;
/* 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];
您在 i == m
时访问 L[m]
元素。这是未定义的行为,作为从 0
索引的数组,这是对 m + 1
元素的访问。
在访问长度为 n
:
L[i]
数组中的 n + 1
元素期间,在下一个循环中出现同样的问题
for (int j=0; j<=n; j++)
{
// Code skipped
L[i][j] = 0;