From: Mike Frysinger Date: Thu, 21 Oct 2010 15:51:53 -0400 Subject: [U-Boot] [PATCH] Prevent malloc with size 0 In-Reply-To: References: <4CC006B1.8000905@intracomdefense.com> <20101021113254.8B04D136320@gemini.denx.de> Message-ID: <201010211551.58419.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thursday, October 21, 2010 07:45:10 Joakim Tjernlund wrote: > Wolfgang Denk wrote on 2010/10/21 13:32:54: > > Joakim Tjernlund you wrote: > > > > - if ((long)bytes < 0) return 0; > > > > + if ((long)bytes <= 0) return 0; > > > > > > I think you should return some impossible ptr value =! NULL > > > Size 0 not really an error. > > > > It is legal for malloc() to return NULL in case of size==0, > > and for the sake of simplicity I recommend we do just that. > > Yes, but not very useful. Glibc does not return NULL it is useful for malloc(0) == NULL. the glibc behavior is downright obnoxious. we disable this for uClibc and dont see problems. if anything, we catch accidental programming mistakes which then get fixed. why exactly do you want malloc(0) to return valid memory ? i would rather have u-boot return an error. -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20101021/751d818a/attachment.pgp