Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Oct 1996 18:53:01 +0930 (CST)
From:      Michael Smith <msmith@atrad.adelaide.edu.au>
To:        danny@panda.hilink.com.au (Daniel O'Callaghan)
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: libc string routines don't check for NULL pointers
Message-ID:  <199610220923.SAA15249@genesis.atrad.adelaide.edu.au>
In-Reply-To: <Pine.BSF.3.91.961022180422.548J-100000@panda.hilink.com.au> from "Daniel O'Callaghan" at Oct 22, 96 06:12:44 pm

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel O'Callaghan stands accused of saying:
> 
> 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.

No.

> 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?

It is _entirely_ the user's problem.  A null pointer references nothing,
not an empty string.  It is not helpful from the debugging point of view
not to have these errors reported as early as possible.

It is unacceptable to penalise working applications for the questionable
benefit that this would bring.

> Danny

-- 
]] Mike Smith, Software Engineer        msmith@atrad.adelaide.edu.au    [[
]] Genesis Software                     genesis@atrad.adelaide.edu.au   [[
]] High-speed data acquisition and      (GSM mobile)  <FOUND!>          [[
]] realtime instrument control          (ph/fax)  +61-8-8267-3493       [[
]] Collector of old Unix hardware.      "Where are your PEZ?" The Tick  [[



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610220923.SAA15249>