leetcode练习算法时遇到的调试bug的解决记录

指针使用越界:

1、free(): invalid next size (fast): 0x0000000001d294d0 ***

使用malloc方法动态分配指针指向的空间,实际在使用时超出了声明的空间,因此指针被污染了。出错代码如下:

    struct TreeNode*** temp=(struct TreeNode ***)malloc(sizeof(struct TreeNode**)*depth);//动态分配depth行的数组

    for(i=0;i<depth;i++)
    {
        temp[i+1]=(struct TreeNode **)malloc(sizeof(struct TreeNode*)*tempLen);
        //实际使用时未考虑到temp指针的边界,当i=depth-1时此处越界了,因此temp指针被污染
    }

猜你喜欢

转载自blog.csdn.net/y___y___/article/details/81807921
今日推荐