title | description | ms.date | f1_keywords | helpviewer_keywords | |||
---|---|---|---|---|---|---|---|
Error: allocation-size-too-big |
Source examples and live debug screenshots for allocation-size-too-big errors. |
03/02/2021 |
|
|
Address Sanitizer Error: allocation-size-too-big
This example shows the error found when an allocation is too large for the heap. Example sourced from LLVM compiler-rt test suite.
// example1.cpp
// allocation-size-too-big error
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
int x = 1000;
int y = 1000;
__declspec(noinline) void bad_function() {
char* buffer = (char*)malloc(x * y * x * y); //Boom!
memcpy(buffer, buffer + 8, 8);
}
int main(int argc, char **argv) {
bad_function();
return 0;
}
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/allocation-size-too-big-example-1.png" alt-text="Screenshot of debugger displaying allocation-size-too-big 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