CppCon 2016: Nicholas Ormrod “The strange details of std::string at Facebook"
Video Statistics and Information
Channel: CppCon
Views: 80,007
Rating: 4.9151397 out of 5
Keywords: Nicholas Ormrod, CppCon 2016, Computer Science (Field), + C (Programming Language), Bash Films, conference video recording services, conference recording services, nationwide conference recording services, conference videography services, conference video recording, conference filming services, conference services, conference recording, conference live streaming, event videographers, capture presentation slides, record presentation slides, event video recording
Id: kPR8h4-qZdk
Channel Id: undefined
Length: 31min 18sec (1878 seconds)
Published: Wed Oct 05 2016
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
What am I not understanding about the amazing bug that Mark Williams found?
So, you have a 128 byte string and you've gotten rid of the null terminator. Did you malloc 128 bytes or 129 bytes for "data" ?
If they malloc'd 128 bytes, then what on earth made them think it was ok to write a null terminator to data[128] in the first place? And in that case, it was broken BEFORE they added the if statement, right?
If they malloc'd 129 bytes, then it would seem that their malloc is completely broken if it's a bug to check data[128] and write 0 to it if it's not 0.
I watched this live. I knew of Andrei's thing with
\0
before, it's one of those amazing tricks in programming. Great talk. This is the closest we got to having Andrei at CppCon 2016.The new GCC strings could also do the '\0' trick, if they would move the size to the end; so if the layout is
{data,capacity,junk,size}
. Then capacity and junk can contain 16 chars, while the '\0' is in the first byte of size. This is true on big endian machines when size is small, but for little endian machines you need to do something else. Either storing the size as a big endian/middle endian number, or storingsize-16
.Anyone have transcript or article link?
What was the gains of lazily writing the null terminator?
So, how did they fix the issue with c_str()? He says it's too slow to write the null terminator with every call, and it's undefined behavior to check if it's there before it's been written, so what did they do?