3 ms·
So, if following the recommended C++ practices of mostly using std containers, ASan and UBSan are mostly useless?
by simiones 4y ago
So, if following the recommended C++ practices of mostly using std containers, ASan and UBSan are mostly useless?
- synergy20 4y agocontainers are not thread safe though, so the thread safe sanitizer will be useful there. ASAN and UBSAN are supposed to be handled by containers internally with RAII if they're used correctly, I still turn on both ASAN and UBSAN to catch bugs, it does not hurt.
- simiones 4y agoAs 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'