4 ms·
As shown in the article, the following code invokes UB in user code, and is not directly detected by ASAN or UBSAN: std::vector<int> c; c.pop_back(); //pop
by simiones 4y ago
As shown in the article, the following code invokes UB in user code, and is not directly detected by ASAN or UBSAN:
std::vector<int> c;
c.pop_back(); //pop_back() on empty vector is UB, per the library documentation
int j = c[0]; //also UB, not sure if would be detected
This code is fully RAII compliant, but wrong.
- menaerus 4y agoIt only takes a tiny effort to prove your ignorance with the exact example you gave. https://gcc.godbolt.org/z/x4sbTWxrY https://gcc.godbolt.org/z/x4sbTWxrY ASM generation compiler returned: 0 Execution build compiler returned: 0 Program returned: 0 /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:1320:2: runtime error: applying non-zero offset 18446744073709551612 to null pointer /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:1124:34: runtime error: reference binding to null pointer of type 'value_type' /app/example.cpp:7:14: runtime error: load of null pointer of type 'value_type'