leetcode上报错:
=================================================================
==42==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60c000000888 at pc 0x00000034f486 bp 0x7ffd5554bb10 sp 0x7ffd5554bb08
READ of size 8 at 0x60c000000888 thread T0
#4 0x7fb0243d90b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
Address 0x60c000000888 is a wild pointer.
Shadow bytes around the buggy address:
0x0c187fff80c0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x0c187fff80d0: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
0x0c187fff80e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fa
0x0c187fff80f0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c187fff8100: 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa
=>0x0c187fff8110: fa[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8150: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8160: 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
==42==ABORTING
leetcode使用AddressSanitizer检查内存是否存在非法访问。报此错,主要是访问了非法内容。
解决方法:数组访问越界,导致此错,后来发现是在访问二维数组的边界row和col弄反了。。
【注意】
LeetCode系统在执行代码时,系统都会判断数组越界问题,并直接报错,根据经验leetcode在用到数组或指针时,做两种处理:
- 1.定义指针时,需要申请内存块,如 int* data = malloc(SIZE * sizeof(int));后面访问指针时,不要大于SIZE值的地址范围。
- 2.定义数组,如int data[SIZE] 后,访问数组时,不要大于SIZE值的地址范围。