From owner-freebsd-bugs Thu Oct 5 18:56:22 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id SAA03086 for bugs-outgoing; Thu, 5 Oct 1995 18:56:22 -0700 Received: from dca.net (dca.net [204.183.80.2]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id SAA03081 for ; Thu, 5 Oct 1995 18:56:19 -0700 Received: from dca.net (localhost.dca.net [127.0.0.1]) by dca.net (8.6.12/8.6.12) with SMTP id VAA09296; Thu, 5 Oct 1995 21:56:15 -0400 Date: Thu, 5 Oct 1995 21:56:13 -0400 (EDT) From: Andrew White To: Stefan Esser cc: bugs@freebsd.org Subject: Re: bug with gcc 2.6.2? In-Reply-To: <199510051000.AA00067@Sysiphos> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-bugs@freebsd.org Precedence: bulk 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 > 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.