Something went wrong. Try again.
A Tour of C++ for experienced programmers, as if C++26 is the only version that ever existed.
Something went wrong. Try again.
12345678910111213141516171819// DEMO: deliberately wrong. This file exists to produce a sanitizer report.// Run under AddressSanitizer, the read past the end of the vector storage// reports heap-buffer-overflow://// ==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000fc// READ of size 4 at 0x6020000000fc thread T0// #0 ... std::__1::__format::__create_format_arg ... format_arg_store.h:191// ...// #8 ... in main ch01_overflow.cpp:13
#include <print>#include <vector>
int main() { std::vector<int> v{1, 2, 3}; volatile std::size_t past_the_end = v.size(); // volatile: defeat constant folding std::println("{}", v.data()[past_the_end]);}