Skip to content

[Solved] ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000d4 at pc 0x0000003a4fa9 bp 0x7ffedf29d730 sp 0x7ffedf29d728 READ of size 4 at 0x6020000000d4 thread T0

When I was solving LeetCode questions recently, I got an error that did not provide any line number:

ERROR: AddressSanitizer: heap-buffer-overflow on address

This is troublesome, and suddenly I don’t know how to debug.

I checked it on the Internet and found that Address Sanitizer is a tool to check whether the memory access is wrong.

Generally, when the compiler is executed on the local side, because there is no setting, it is almost certainly not encountered, because C/C++ compiler does not do boundary checking for your memory access.

But your code run in LeetCode, they strictly controlled not to access the memory block that is not requested by you. So the error message will be return when the memory block is requested incorrectly.


Solution

The solution is simple but troublesome: make sure that you have not made a request that exceeds the memory boundary.

One of the most common situation is to call an index element that exceeds the length of the array.

On the Internet, many people have added judgments to prevent them from accessing the wrong index. This is also a possible method.

Of course, if you want to completely solve this problem, you can also install the Address Sanitizer tool in your own local environment to test.


References


Read More

Leave a Reply