我的程序因以下几行而崩溃:
警告:HEAP [maze.exe]:警告:00392F30 处的堆块在 00392F3B 处修改,请求大小为 3
我正在为字符串动态分配空间
int userReq() {
char **maze=NULL;
char *pchar;
int i, test_cases, cur_test=0;
int row, col;
/* gather the amount of test cases */
scanf("%d", &test_cases);
do{
scanf("%d",&row);
scanf("%d",&col);
/* allocate memory for char pointer row-wise */
maze = (char **) malloc(row*sizeof(char*));
for(i=0;i<row;i++)
/* for each cell allocate the num of chars in cell */
maze[i] = (char *) malloc(col*sizeof(char));
for(i=0;i<row;i++)
scanf("%s",maze[i]);
/* this function does modify the maze by changing some of the spots to a different char */
CallSomeFunctionHere(maze);
/* free first the cells then the entire block */
for(i=0;i<row;i++)
free(maze[i]);
free(maze);
cur_test = cur_test + 1;
}while(cur_test < test_cases);
/* if we were successful then exit program with
success */
return 0;
}
我的程序在执行逻辑然后尝试释放内存后崩溃。