r/cpp • • Mar 13 '26

Trusted-CPP - Safe Software Developing in C++ with backward compatibility

https://trusted-cpp.org/

I invite explore the concept of safe software developing in C++ while backward compatibility with legacy code. Please send feedback and constructive criticism on this concept and its implementation. Suggestions for improvement and assistance in the developint are also welcome.

28 Upvotes

15 comments sorted by

View all comments

Show parent comment

3

u/aocregacc Mar 13 '26 edited Mar 13 '26

the vector is reset before the sort (vect = {}). It passes all the sanitizers because libstdc++ just sets the size to 0 but keeps the allocation. You have to turn on _GLIBCXX_SANITIZE_VECTOR for asan to notice, and even then it only notices the access through y, not the bad use of x. _GLIBCXX_DEBUG catches that one I think, but the error message is a bit cryptic for me.

edit: another thing I didn't realize is that vect = {} invokes vector's operator=(std::initializer_list), so it's not like you're move-assigning with an empty vector here. If you do, the allocation would be free'd in this case and asan would fire.

1

u/ts826848 Mar 14 '26

Yeah, I somehow completely missed that line. My apologies for the mistake!