執行報錯,不知道哪個地方出錯了,求助!
題目要求如下:
給定一個二進制矩陣 A,我們想先水平翻轉影像,然后反轉影像并回傳結果。
水平翻轉圖片就是將圖片的每一行都進行翻轉,即逆序。例如,水平翻轉 [1, 1, 0] 的結果是 [0, 1, 1]。
反轉圖片的意思是圖片中的 0 全部被 1 替換, 1 全部被 0 替換。例如,反轉 [0, 1, 1] 的結果是 [1, 0, 0]。
示例 1:
輸入: [[1,1,0],[1,0,1],[0,0,0]]
輸出: [[1,0,0],[0,1,0],[1,1,1]]
解釋: 首先翻轉每一行: [[0,1,1],[1,0,1],[0,0,0]];
然后反轉圖片: [[1,0,0],[0,1,0],[1,1,1]]
示例 2:
輸入: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
輸出: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
解釋: 首先翻轉每一行: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]];
然后反轉圖片: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
說明:
1 <= A.length = A[0].length <= 20
0 <= A[i][j] <= 1
來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/flipping-an-image
著作權歸領扣網路所有。商業轉載請聯系官方授權,非商業轉載請注明出處。
這是初始的代碼模板
/**
* 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().
*/
int** flipAndInvertImage(int** A, int ASize, int* AColSize, int* returnSize, int** returnColumnSizes){
}
/**
* 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().
*/
int** flipAndInvertImage(int** A, int ASize, int* AColSize, int* returnSize, int** returnColumnSizes)
{
int i,j;
*AColSize = ASize;
*returnSize = ASize; //回傳的陣列大小
returnColumnSizes = (int**)malloc(ASize*sizeof(int*)); //生成指標陣列
for(i=0; i<ASize; i++)
{
returnColumnSizes[i] = (int*) malloc(ASize*sizeof(int));
for(j=0; j<ASize; j++)
{
returnColumnSizes[i][j] = !(A[i][ASize-1-j]);
}
}
return returnColumnSizes;
}
報錯如下:
=================================================================
==45==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000dc at pc 0x0000004051a2 bp 0x7ffee89c3870 sp 0x7ffee89c3860
READ of size 4 at 0x6020000000dc thread T0
#3 0x7fabf9e6282f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
0x6020000000dc is located 0 bytes to the right of 12-byte region [0x6020000000d0,0x6020000000dc)
allocated by thread T0 here:
#0 0x7fabfae7e078 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c078)
#3 0x7fabf9e6282f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
Shadow bytes around the buggy address:
0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff8000: fa fa 00 04 fa fa 00 04 fa fa 00 04 fa fa 00 04
=>0x0c047fff8010: fa fa 00 04 fa fa 00 04 fa fa 00[04]fa fa fd fa
0x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 fa
0x0c047fff8030: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 fa
0x0c047fff8040: fa fa fd fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==45==ABORTING
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/38239.html
標籤:C語言
