Date: Wed, 06 Jul 2005 13:46:41 -0700 From: Maksim Yevmenkin <maksim.yevmenkin@savvis.net> To: Giorgos Keramidas <keramida@freebsd.org> Cc: freebsd-hackers@freebsd.org, Stefan Sperling <stsp@stsp.in-berlin.de> Subject: Re: bus error in strsep Message-ID: <42CC4331.7080703@savvis.net> In-Reply-To: <20050706203924.GB6160@gothmog.gr> References: <20050706185536.GA4700@dice.seeling33.de> <42CC2C36.7090003@savvis.net> <20050706203924.GB6160@gothmog.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
>>>int main(int argc, char* argv[]) >>>{ >>> char *c = "whats:your:name:buddy?"; >> >> ^^^^^^^^^^^^^^^^ that is not read only copy. you can not write >>into it. replace it with >> >> char *c = strdup("whats:your:name:buddy?"); > > Or the following: > > char c[] = "whats:your:name:buddy?"; > > which doesn't require a free() operation when you're done with c[]. actually it still will crash :) beetle% cat 5.c #include <string.h> int main(int argc, char* argv[]) { char c[] = "whats:your:name:buddy?"; strsep((char **) &c, ":"); return (0); } beetle% gcc -Wall -ggdb 5.c beetle% ./a.out Segmentation fault (core dumped) so something like this #include <string.h> int main(int argc, char* argv[]) { char c[] = "whats:your:name:buddy?", *s = c; strsep((char **) &s, ":"); return (0); } will work too. max
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?42CC4331.7080703>