本文主要是介绍LeetCode 报错 heap-buffer-overflow的解决方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题描述
在leetcode刷题过程中,遇到运行报错: heap-buffer-overflow*****,详见如下:
=================================================================
==30==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000000474 at pc 0x000000415213 bp 0x7fff431db270 sp 0x7fff431db268
WRITE of size 4 at 0x603000000474 thread T0#2 0x7f885ac102e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)0x603000000474 is located 0 bytes to the right of 20-byte region [0x603000000460,0x603000000474)
allocated by thread T0 here:#0 0x7f885c635ce0 in operator new(unsigned long) (/usr/local/lib64/libasan.so.5+0xe9ce0)#4 0x7f885ac102e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)Shadow bytes around the buggy address:0x0c067fff8030: fa fa fd fd fd fd fa fa fd fd fd fa fa fa fd fd0x0c067fff8040: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa0x0c067fff8050: fd fd fd fa fa fa fd fd fd fa fa fa 00 00 04 fa0x0c067fff8060: fa fa fd fd fd fa fa fa 00 00 04 fa fa fa 00 000x0c067fff8070: 04 fa fa fa 00 00 04 fa fa fa 00 00 04 fa fa fa
=>0x0c067fff8080: 00 00 00 fa fa fa fd fd fd fa fa fa 00 00[04]fa0x0c067fff8090: fa fa 00 00 04 fa fa fa 00 00 04 fa fa fa 00 000x0c067fff80a0: 04 fa fa fa 00 00 04 fa fa fa fa fa fa fa fa fa0x0c067fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa0x0c067fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa0x0c067fff80d0: 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: 00Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: faFreed heap region: fdStack left redzone: f1Stack mid redzone: f2Stack right redzone: f3Stack after return: f5Stack use after scope: f8Global redzone: f9Global init order: f6Poisoned by user: f7Container overflow: fcArray cookie: acIntra object redzone: bbASan internal: feLeft alloca redzone: caRight alloca redzone: cb
==30==ABORTING
问题分析
通过某度,查到leetcode使用AddressSanitizer检查内存是否存在非法访问。报此错,主要是访问了非法内容。
解决方法
排查代码,发现数组访问越越,导致此错,将申请的数组空间加大,问题解决。
这篇关于LeetCode 报错 heap-buffer-overflow的解决方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!