Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Oct 1996 07:12:09 +0900 (JST)
From:      Michael Hancock <michaelh@cet.co.jp>
To:        Julian Elischer <julian@whistle.com>
Cc:        "Daniel O'Callaghan" <danny@panda.hilink.com.au>, freebsd-hackers@FreeBSD.org
Subject:   Re: libc string routines don't check for NULL pointers
Message-ID:  <Pine.SV4.3.93.961023070945.8318B-100000@parkplace.cet.co.jp>
In-Reply-To: <326D1817.1CFBAE39@whistle.com>

next in thread | previous in thread | raw e-mail | index | archive | help
If the functions had assertions, then people who look at the code wouldn't
have to ask anymore.  The assertions would be preprocessed away by
default, but the code would have clearer specifications.

Regards,


Mike Hancock

On Tue, 22 Oct 1996, Julian Elischer wrote:

> Daniel O'Callaghan wrote:
> 
> This comes up about every 6 months for the last 10 years on the
> newsgroups..
> the functions are SUPPOSED to segv
> 
> you are NOT SUPPOSED TO call them with null pointers
> you are supposed to CHECK THEM BEFORE.
> 
> this is so that yuou can check a string is non null,
> use it in 57 consecutive operations
> and have only wasted teh effort of checking it once.
> 
> fix the program.
> 
> 
> > 
> > The string comparison (and other) routines in libc don't check for null
> > pointers being passed.  This results in SEGVs if one or both of the
> > string pointers being passed is NULL.  I can see a religious debate here,
> > but I'm going to raise the issue:  Should str*cmp() handle NULL arguments.
> > 
> > I have made the very simple change necessary to strcmp() for it to return
> > 
> >         0 - strings are the same, or pointers are both NULL
> >         < 0 - s1 < s2, or s1 == NULL
> >         > 0 - s1 > s2 or s2 == NULL
> > 
> > I'd like to see my changes made to libc, but what do others think -
> > should it be just "the programmer's stupid fault" if (s)he passes a NULL
> > pointer to these routines, or should the routines handle NULL?
> > 
> > Danny
> 

--
michaelh@cet.co.jp                                http://www.cet.co.jp
CET Inc., Daiichi Kasuya BLDG 8F 2-5-12, Higashi Shinbashi, Minato-ku,
Tokyo 105 Japan              Tel: +81-3-3437-1761 Fax: +81-3-3437-1766




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SV4.3.93.961023070945.8318B-100000>