讨论/算法和数据结构/在C语言中提交有个测试用例出现这个错误是什么意思?/
在C语言中提交有个测试用例出现这个错误是什么意思?

AddressSanitizer:DEADLYSIGNAL

==45==ERROR: AddressSanitizer: stack-overflow on address 0x7ffcb645f000 (pc 0x000000401a3a bp 0x7ffcb645e830 sp 0x7ffcb645e6a0 T0)
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer: nested bug in the same thread, aborting.

/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
#define MAX_SIZE 10000
 typedef struct Pos{
     int x ;
     int y ;
 }Pos;
int** updateMatrix(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes){

//队列
struct Pos *quee = (struct Pos*)malloc(sizeof(struct Pos)* MAX_SIZE);
int head =0;
int tail =0;
//将为0的位置入队
*returnSize = matrixSize ;
for(int i =0 ; i < matrixSize ;i++){
   ( *returnColumnSizes)[i] = matrixColSize[0];
}
if(matrixColSize[0] == 1) return matrix;
if(matrixColSize[0] == 1 ){
    for(int i =0 ; i < matrixSize ; i++){
        if(matrix[i][0] == 0)continue;
        if(i+1 < matrixSize  && matrix[i-1][0] == 0 ){
            continue;
        }
        if(i-1 > 0  && matrix[i-1][0] >0){
                matrix[i][0] = matrix[i-1][0]+1;
        }
    }
}

for(int i =0 ; i < matrixSize ; i++){
    for(int j =0  ; j < matrixColSize[0] ; j++ ){
        if(matrix[i][j] == 0 ){
            (quee[tail]).x =i;
            quee[tail].y = j;
            tail++;
        }else{
            matrix[i][j] =-1;
        }
    }
}


//BFS
int dx[4] ={ 1, -1,  0 ,  0 };
int dy[4] ={ 0,   0, -1  , 1 };

while( head != tail){
    //遍历队首上下左右
    for(int  i = 0 ; i <4 ;i++){
        //判断边界问题
       
        int x = dx[i] +quee[head].x;
        int y = dy[i] +quee[head].y;
        
        if( x >= 0 && x < matrixSize && y >=0 && y < matrixColSize[0]  ){
            //如果没被访问,入队
            if(matrix[x][y]== -1 ){
               quee[tail].x =x ;
               quee[tail].y =y ;
               tail++;
                matrix[x][y] =matrix[quee[head].x][quee[head].y]+1;
                continue;             
            }
             if(matrix[x][y]!= 0 && matrix[x][y] > matrix[quee[head].x][quee[head].y]+1 ){
                         matrix[x][y] =  matrix[quee[head].x][quee[head].y]+1;
                  }

        }
    }
    head++;
}

return matrix;
}

题目542. 01 矩阵

展开讨论
派大星发起于 2020-04-15

栈溢出了