From owner-freebsd-hackers Tue Oct 22 02:23:19 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id CAA16707 for hackers-outgoing; Tue, 22 Oct 1996 02:23:19 -0700 (PDT) Received: from genesis.atrad.adelaide.edu.au (genesis.atrad.adelaide.edu.au [129.127.96.120]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id CAA16696 for ; Tue, 22 Oct 1996 02:23:13 -0700 (PDT) Received: from msmith@localhost by genesis.atrad.adelaide.edu.au (8.6.12/8.6.9) id SAA15249; Tue, 22 Oct 1996 18:53:02 +0930 From: Michael Smith Message-Id: <199610220923.SAA15249@genesis.atrad.adelaide.edu.au> Subject: Re: libc string routines don't check for NULL pointers To: danny@panda.hilink.com.au (Daniel O'Callaghan) Date: Tue, 22 Oct 1996 18:53:01 +0930 (CST) Cc: freebsd-hackers@freebsd.org In-Reply-To: from "Daniel O'Callaghan" at Oct 22, 96 06:12:44 pm MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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) [[ ]] realtime instrument control (ph/fax) +61-8-8267-3493 [[ ]] Collector of old Unix hardware. "Where are your PEZ?" The Tick [[