Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Oct 1996 11:53:11 -0700
From:      Julian Elischer <julian@whistle.com>
To:        "Daniel O'Callaghan" <danny@panda.hilink.com.au>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: libc string routines don't check for NULL pointers
Message-ID:  <326D1817.1CFBAE39@whistle.com>
References:  <Pine.BSF.3.91.961022180422.548J-100000@panda.hilink.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?326D1817.1CFBAE39>