Date: Thu, 5 Oct 1995 11:00:43 +0100 From: se@zpr.uni-koeln.de (Stefan Esser) To: Andrew White <awhite@dca.net> Cc: bugs@freebsd.org Subject: Re: bug with gcc 2.6.2? Message-ID: <199510051000.AA00067@Sysiphos> In-Reply-To: Andrew White <awhite@dca.net> "bug with gcc 2.6.2?" (Oct 5, 2:42)
next in thread | previous in thread | raw e-mail | index | archive | help
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>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510051000.AA00067>