小编use*_*103的帖子

Valgrind:大小为1的读数无效

我遇到了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时,它说:

Invalid read of size 1
at 0x401569: main (:395)
Address 0x0 is not stack'd malloc'd or (recently) free'd
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚这个程序有什么问题.

c valgrind pointers

18
推荐指数
2
解决办法
5万
查看次数

标签 统计

c ×1

pointers ×1

valgrind ×1