Dangling in French and English
summary
Code demonstrates that taking a char from string::c_str() inside a std::vector then push_backing more elements can either be safe or crash depending on small string optimization. A 18‑char French string allocates on the heap so the pointer survives vector growth; a 15‑char English string fits SSO and c_str() points into the string object, so after reallocation the pointer dangles and causes a segfault. SSO threshold 16 c_str() pointing into short-string buffer*
AI-written summary · about
related talks
19mDestructuring Rust strings
28mOptimizing A String Class for Computer Graphics in Cpp
58mUnderstanding and Mastering C++'s Complexity
55mStringViews, StringViews everywhere!
01h 02mEmbedded Friendly C++: Features That Make a Difference
33mC++: Unexpected Behaviour
01h 02mBack to Basics: Almost Always Vector
01h 04mEffective Qt
