*BSD News Article 44733


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!news.kei.com!news.mathworks.com!gatech!EU.net!Germany.EU.net!Dortmund.Germany.EU.net!not-for-mail
From: bs@Germany.EU.net (Bernard Steiner)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Major strcmp bug under BSD 2.0?
Date: 31 May 1995 14:34:38 +0200
Organization: EUnet Deutschland GmbH, Dortmund, Germany
Lines: 27
Message-ID: <3qhnou$2cb@Germany.EU.net>
References: <3qfn52$188j@troy.la.locus.com> <GENE.95May30223449@starkhome.cs.sunysb.edu>
NNTP-Posting-Host: qwerty.germany.eu.net


In article <GENE.95May30223449@starkhome.cs.sunysb.edu>, gene@starkhome.cs.sunysb.edu (Gene Stark) writes:
|> >Am I imagining things or is there a bug in BSD 2.0's strcmp() function?
|> >If either of the string parameters is NULL the program core dumps.
|> >Isn't this a major bug? (Making the OS pretty much useless). Is there 
|> >a simple fix for this ? 
|> 
|> No, it is an example of a subroutine that only works under conditions
|> that must be ensured by the caller.  This is probably done for efficiency
|> reasons: if it always checks if its arguments are NULL, then you pay
|> every time, even if as a clever programmer you are able to guarantee
|> without checking that you always pass non-NULL arguments.

What exactly is the meaning of passing a NULL pointer, anyway ? And in how far
is that any different from passing a pointer to any old memory location
outside your assigned address space ?

What should be the result of

(a) strcmp((char*)0, (char*)0) as opposed to strcmp("", "")
(b) strcmp((char *)0, "") as opposed to strcmp("", "")
(c) strcmp("", (char *)0) as opposed to strcmp("", "")
(d) strcmp((char *)-1, (char *)0) as opposed to strcmp((char*)0, (char*)0)

and so on ?

Bernard