*BSD News Article 9462


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA5804 ; Fri, 01 Jan 93 01:56:25 EST
Path: sserve!manuel.anu.edu.au!munnari.oz.au!uunet!usc!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!mintaka.lcs.mit.edu!ai-lab!hal.gnu.ai.mit.edu!mycroft
From: mycroft@hal.gnu.ai.mit.edu (Charles Hannum)
Newsgroups: comp.unix.bsd
Subject: Re: [386bsd] GNU malloc in favor of BSD malloc in libc - shall we vote?
Date: 1 Jan 1993 03:10:48 GMT
Organization: /etc/organization
Lines: 21
Message-ID: <1i0cnoINNiu2@life.ai.mit.edu>
References: <JKH.92Dec31154004@whisker.lotus.ie> <1hvu79INNjqq@ftp.UU.NET> <1993Jan1.001332.15123@serval.net.wsu.edu>
NNTP-Posting-Host: hal.gnu.ai.mit.edu


In article <1993Jan1.001332.15123@serval.net.wsu.edu> hlu@eecs.wsu.edu
(H.J. Lu) writes:
>
> Another `feature' in GNU malloc is malloc (0) returns NULL.

According to ANSI, malloc(0) is implementation-defined.  I believe some
systems intentionally return a bogus(?) address so that sloppy programs
don't have to think about it.

Obviously, you can't write or read at the address returned by malloc(0)
anyway; what difference can it really make?  The only place I've seen a
problem with returning NULL is functions like xmalloc() which check the
address from malloc() to see whether or not it succeeded, and these are
trivial to modify so that they do not depend on implementation-specific
behavior.

-- 
 \  /   Charles Hannum, mycroft@ai.mit.edu
 /\ \   PGP public key available on request.  MIME, AMS, NextMail accepted.
Scheme  White heterosexual atheist male (WHAM) pride!