Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.92 KB

error-allocation-size-too-big.md

File metadata and controls

60 lines (44 loc) · 1.92 KB
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
allocation-size-too-big
allocation-size-too-big error
AddressSanitizer error allocation-size-too-big

Error: allocation-size-too-big

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.

Example

// 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

Resulting error

:::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.":::

See also

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