Chasing down a bug while using strtok.
Posted Tue, 19 Jun 2007
While coding tonight, I spent *at least* 20 minutes trying to figure out why my
program was crashing in strtok_r. Turns out I forgot that strtok (and strtok_r)
modify the string in-place (with null bytes), and I was passing in a string
literal.
In C, "string literals" are stored in a special read-only bit of the program, so if you try to modify them your program crashes. I was calling a function several levels up with a string literal trying to test functionality and it kept crashing with sigbus. Wee. Lesson relearned ;)