---
title: Overflow of C++ containers
framework: xcode
role: article
role_heading: Article
path: xcode/overflow-of-c-containers
---

# Overflow of C++ containers

Detects when you access a C++ container outside its bounds.

## Overview

Overview Use this check to detect when you access a libc++ container beyond the region [container.begin(), container.end()], even when the accessed memory is in a heap-allocated buffer the container uses internally. Available in Xcode 7 and later. note: This check is enabled by default. In Xcode versions prior to version 26, it was disabled by default. See Disabling Container Overflow Checks to disable it. Vector overflow in C++ In the following example, the vector variable has valid indexes in the range [0,2], but the accessed index is 3, which causes an overflow: std::vector<int> vector; vector.push_back(0); vector.push_back(1); vector.push_back(2); auto *pointer = &vector[0]; return pointer[3]; // Error: out of bounds access for vector Solution Add a bounds check before attempting to access a container at a specific index. Disabling Container Overflow Checks note: The Enable C++ Container Overflow Checks build setting no longer has any effect in Xcode 26 onwards. You may encounter a false-positive ‘Container overflow’ error when code that isn’t compiled with Address Sanitizer modifies a container. For container overflow checks to work correctly, you need to compile all code with Address Sanitizer. If you can’t do this, turn off container overflow checks using one of the following methods: #ifdef __cplusplus extern "C" { #endif #include <sanitizer/asan_interface.h>

__attribute__((used, visibility("default"))) const char *__asan_default_options() {     return "detect_container_overflow=0"; } #ifdef __cplusplus } #endif If you set the Exported Symbols File build setting, then also add ___asan_default_options to the file to ensure that the system exports the symbol. If you set the detect_container_overflow option in both the __asan_default_options function, and the ASAN_OPTIONS environment variable, the system uses the value in the environment variable.

## See Also

### Address Sanitizer

- [Use of deallocated memory](xcode/use-of-deallocated-memory.md)
- [Deallocation of deallocated memory](xcode/deallocation-of-deallocated-memory.md)
- [Deallocation of nonallocated memory](xcode/deallocation-of-nonallocated-memory.md)
- [Use of stack memory after function return](xcode/use-of-stack-memory-after-function-return.md)
- [Use of out-of-scope stack memory](xcode/use-of-out-of-scope-stack-memory.md)
- [Overflow and underflow of buffers](xcode/overflow-and-underflow-of-buffers.md)
