use*_*103 18 c valgrind pointers
我遇到了valgrind的问题:这是我的程序(错误出现的主要部分):
int main()
{
char comanda[N];
....
char *p;
while( fgets(comanda,100,stdin)!=NULL)
{
p=strtok(comanda," \n");
if (strcmp(comanda,"INIT")==0)
{
p=strtok(NULL," ");
Init(n);
}
395 >>if (strcmp(p,"DUMP")==0)
{
Dump(n);}
if (strcmp(p,"ALLOC")==0)
{
Alloc(j,n);
}
....return 0;}
Run Code Online (Sandbox Code Playgroud)
当我运行valgrind时,它说:
Run Code Online (Sandbox Code Playgroud)Invalid read of size 1 at 0x401569: main (:395) Address 0x0 is not stack'd malloc'd or (recently) free'd
我无法弄清楚这个程序有什么问题.
Mat*_*son 29
怎么读这个:
读取大小为1无效
你的程序试图从Valgrind不喜欢的地方读取一个字节.
在0x401569:主要(:395)
代码中的位置发生了(显然strcmp已经内联)
地址0x0没有堆叠malloc'd或(最近)free'd
它读取的地址是什么 - 0x0是"NULL".声明的其余部分只是说它为什么无效(它不是来自堆栈,它不是你从malloc得到的东西,最近没有被释放).提到"最近"因为valgrind跟踪有限数量的释放释放的内存,所以它不能肯定地说它没有释放一百万个自由 - 在这种情况下它不是,但如果你看到这样的消息,它可能因为它在很久以前被释放而变得无效.地址不会为零(或接近零).
归档时间: |
|
查看次数: |
54935 次 |
最近记录: |