photo
Jordan Sissel
geek

Tue, 19 Jun 2007

Chasing down a bug while using strtok.

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 ;)

Comments: 4 (view comments)
Tags: , ,
Permalink: /geekery/strtok-gotchas
posted at: 06:15

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< June 2007 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati