Date: Thu, 5 Oct 1995 21:56:13 -0400 (EDT) From: Andrew White <awhite@dca.net> To: Stefan Esser <se@zpr.uni-koeln.de> Cc: bugs@freebsd.org Subject: Re: bug with gcc 2.6.2? Message-ID: <Pine.BSF.3.91.951005215533.9169F-100000@dca.net> In-Reply-To: <199510051000.AA00067@Sysiphos>
next in thread | previous in thread | raw e-mail | index | archive | help
Thanks for your response. Of course you are right, a null string and a null pointer are not the same. However, it would be nice if the str* functions would not SIGSEV when called with a null pointer, but rather failed more nicely. -aw On Thu, 5 Oct 1995, Stefan Esser wrote: > On Oct 5, 2:42, Andrew White wrote: > } Subject: bug with gcc 2.6.2? > } FreeBSD bugs list: > } > } The following code generates a segmentation violation using gcc 2.6.2 as > } shipped with FreeBSD 2.0-RELEASE. It shouldn't! It seems as if any of > } the string functions (strcmp, strcpy, etc) bomb when invoked with a null > } string. > > This is not a compiler error, but intended behaviour ... > > NULL is not a string, but a pointer to NO string. > > FreeBSD on purpose makes address 0 unavailable, just to > catch such errors (as just about any other Unix system). > > } I compiled this using gcc 2.3.3 under AIX 3.2.5, and it works as expected > } (prints "x is -1" when run). I am compiling this program (I called it > } test.c) with: "gcc -o test test.c"... am I missing something obvious?? > > } s=NULL; > } > } x=strcmp(s,"test"); > > Yes. The test result is undefined, and the system lets > you know. If you want to use a NULL pointer to imply an > empty string, then you better code this as: > > x=strcmp(s ? s : "", "test"); > > assuming that the second parameter in fact is not a > constant string, but variable and known to not be > another NULL pointer ... > > Regards, STefan > > -- > Stefan Esser, Zentrum fuer Paralleles Rechnen Tel: +49 221 4706021 > Universitaet zu Koeln, Weyertal 80, 50931 Koeln FAX: +49 221 4705160 > ============================================================================== > http://www.zpr.uni-koeln.de/staff/esser/esser.html <se@ZPR.Uni-Koeln.DE> > awhite@dca.net http://www.dca.net/ (work-related) Andrew@White.org http://andrew.white.org/ (personal) DCANET: The Delaware Common Access Network Call (302) 654-1019 or send mail to info@dca.net for more information.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.951005215533.9169F-100000>