From owner-freebsd-bugs Thu Oct 5 03:02:52 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id DAA01131 for bugs-outgoing; Thu, 5 Oct 1995 03:02:52 -0700 Received: from Sysiphos (Sysiphos.MI.Uni-Koeln.DE [134.95.212.10]) by freefall.freebsd.org (8.6.12/8.6.6) with SMTP id DAA01095 for ; Thu, 5 Oct 1995 03:02:03 -0700 Received: by Sysiphos id AA00067 (5.67b/IDA-1.5 for bugs@freebsd.org); Thu, 5 Oct 1995 11:00:44 +0100 Message-Id: <199510051000.AA00067@Sysiphos> From: se@zpr.uni-koeln.de (Stefan Esser) Date: Thu, 5 Oct 1995 11:00:43 +0100 In-Reply-To: Andrew White "bug with gcc 2.6.2?" (Oct 5, 2:42) X-Mailer: Mail User's Shell (7.2.6 alpha(2) 7/9/95) To: Andrew White Subject: Re: bug with gcc 2.6.2? Cc: bugs@freebsd.org Sender: owner-bugs@freebsd.org Precedence: bulk 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