Topic request is as follows:
given A binary matrix A, we want to flip horizontal image first, and then reverse image and returns as A result,
Flip horizontal images is to flip, each row of the reverse order, for example, flip horizontal is the result of [1, 1, 0] [0, 1, 1],
Inverted image mean 0 in all replaced by 1, all replaced by 0, 1, for example, the inversion results of [0, 1, 1] is [1, 0, 0],
Example 1:
Input: [[1, 0], [1, 1], [0, 0]]
Output: [[0, 1], [0, 0], [1,1,1]]
Explanation: first turn over each line: [,1,1 [0], [1, 1], [0, 0]].
Then reverse image: [[0, 1], [0, 0], [1,1,1]]
Example 2:
,1,0,0 input: [[1],,0,0,1 [1], [0,1,1,1], [1,0,1,0]]
,1,0,0 output: [[1], [0,1,1,0], [0,0,0,1], [1,0,1,0]]
Explanation: first turn over each line: [,0,1,1 [0],,0,0,1 [1],,1,1,0 [1], [0,1,0,1]].
Then reverse image: [,1,0,0 [1], [0,1,1,0], [0,0,0,1], [1,0,1,0]]
Description:
1 & lt;=a. ength=A [0]. Length & lt;=20
0 & lt;=A [I] [j] <=1
Source: the power button (LeetCode)
Link: https://leetcode-cn.com/problems/flipping-an-image
Copyright belongs to the collar of the network, commercial reproduced please contact the official authorization, non-commercial reprint please indicate the source,
This is the initial code template
/* ** 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 ().
*/
* * A * * flipAndInvertImage int (int, 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 ().
*/
* * A * * flipAndInvertImage int (int, int ASize, int * AColSize, int * returnSize, int * * returnColumnSizes)
{
int i,j;
* AColSize=ASize;
* returnSize=ASize;//return the array size
ReturnColumnSizes=(int) * * malloc (ASize * sizeof (int *));//generated pointer array
for(i=0; i{
ReturnColumnSizes [I]=(int *) malloc (ASize * sizeof (int));
For (j=0; j{
ReturnColumnSizes [I] [j]=! (A [I] [ASize - 1 - j]);
}
}
Return returnColumnSizes;
}
An error is as follows:
=================================================================
45====ERROR: AddressSanitizer: heap - buffer overflow on the address 0 x6020000000dc at PC bp x7ffee89c3870 sp 0 0 0 x0000004051a2 x7ffee89c3860
The READ of size 4 at 0 x6020000000dc thread T0
# 3 0 x7fabf9e6282f __libc_start_main in (/lib/x86_64 - - the gnu/Linux libc. So. 6 + 0 x2082f)
0 x6020000000dc is located 12 - byte 0 bytes to the right of region [0 x6020000000d0, 0 x6020000000dc)
Allocated by the thread T0 here:
# 0 0 x7fabfae7e078 in malloc (/usr/lib/x86_64 - - the gnu/Linux libasan. So. 5 + 0 x10c078)
# 3 0 x7fabf9e6282f __libc_start_main in (/lib/x86_64 - - the gnu/Linux libc. So. 6 + 0 x2082f)
Shadow bytes around the buggy address:
0 x0c047fff7fc0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0 x0c047fff7fd0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0 x0c047fff7fe0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0 x0c047fff7ff0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 0 x0c047fff8000: fa fa 04 fa fa 04 fa fa 00 04 fa fa 00 04
=> 0 x0c047fff8010: fa fa 00 04 fa fa 00 00 04 fa fa [04] fa fa fd fa
0 x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 fa
0 x0c047fff8030: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 fa
0 x0c047fff8040: fa fa fd fa fa fa fa fa fa fa fa fa fa fa fa fa
0 x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0 x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one Shadow byte represents application 8 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
The Stack right redzone: f3
The Stack after return: f5
Stack the use after the scope: f8
Global redzone: f9
Global init order: f6
Poisoned by the user: f7
The Container overflow: fc
Array cookies: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
====45 ABORTING
CodePudding user response:
Illegal memory accessCodePudding user response:
Original himself did not even get started parameters meaning code word, the following program can/* ** 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 ().
*/
* * A * * flipAndInvertImage int (int, int ASize, int * AColSize, int * returnSize, int * * returnColumnSizes) {
//1 & lt;=a. ength=A [0]. Length & lt;=20 matrix of the square, rows and columns equal
Int * * retArray;
int i,j;
RetArray=(int) * * malloc (ASize * sizeof (int *)); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull