-
Casting type safety to the wind
2008-03-06 16:11 in /tech/HallOfShame
I spent most of yesterday hunting down a segfault in one of our unit tests. Here is a greatly simplified version of the code: can you see the bug?
#include <string> void bar(size_t* len) { *len = 0; } int main(void) { std::string buf; int len = 255; bar((size_t *)&len); return 0; }
Here’s a hint: maybe it doesn’t segfault for you.
Hint #2: the segfault is in basic_string::~basic_string().
(more)