title | description | ms.date | f1_keywords | helpviewer_keywords | |||
---|---|---|---|---|---|---|---|
Error: invalid-allocation-alignment |
Source examples and live debug screenshots for invalid _aligned_malloc errors. |
03/02/2021 |
|
|
Address Sanitizer Error: invalid-allocation-alignment
The _aligned_malloc
function requires a power of 2 for expressing the alignment. We simulate the "external" calculation of some alignment factor using an unoptimized global variable.
// example1.cpp
// invalid-allocation-alignment error
#include <Windows.h>
int ExternalAlign = 5;
int main(){
// this externally calculated alignment of 5 isn't valid.
void* ptr = _aligned_malloc(8,ExternalAlign);
return (ptr == nullptr && errno == EINVAL) ? 0 : -1;
}
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/invalid-allocation-alignment-example-1.png" alt-text="Screenshot of debugger displaying invalid-allocation-alignment 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