| title | Error: use-after-poison | ||
|---|---|---|---|
| description | Source examples and live debug screenshots for use after poison errors. | ||
| ms.date | 03/02/2021 | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
Address Sanitizer Error: Use of poisoned memory
A developer can manually poison memory to customize debugging.
// example1.cpp
// use-after-poison error
#include <stdlib.h>
extern "C" void __asan_poison_memory_region(void *, size_t);
int main(int argc, char **argv) {
char *x = new char[16];
x[10] = 0;
__asan_poison_memory_region(x, 16);
int res = x[argc * 10]; // Boom!
delete [] x;
return res;
}To build and test this example, run these commands in a Visual Studio 2019 version 16.9 or later developer command prompt:
cl example1.cpp /fsanitize=address /Zi
devenv /debugexe example1.exe:::image type="content" source="media/use-after-poison-example-1.png" alt-text="Screenshot of debugger displaying use-after-poison error in example 1.":::
AddressSanitizer overview
AddressSanitizer known issues
AddressSanitizer build and language reference
AddressSanitizer runtime reference
AddressSanitizer shadow bytes
AddressSanitizer cloud or distributed testing
AddressSanitizer debugger integration
AddressSanitizer error examples