Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S268587AbTGIXit (ORCPT ); Wed, 9 Jul 2003 19:38:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S268758AbTGIXhX (ORCPT ); Wed, 9 Jul 2003 19:37:23 -0400 Received: from chaos.analogic.com ([204.178.40.224]:12416 "EHLO chaos.analogic.com") by vger.kernel.org with ESMTP id S268725AbTGIXgD (ORCPT ); Wed, 9 Jul 2003 19:36:03 -0400 Date: Wed, 9 Jul 2003 19:51:01 -0400 (EDT) From: "Richard B. Johnson" X-X-Sender: root@chaos Reply-To: root@chaos.analogic.com To: "H. Peter Anvin" cc: linux-kernel@vger.kernel.org Subject: Re: modutils-2.3.15 'insmod' In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1526 Lines: 58 On Wed, 9 Jul 2003, H. Peter Anvin wrote: > Followup to: > By author: Andreas Schwab > In newsgroup: linux.dev.kernel > > > > "Richard B. Johnson" writes: > > > > |> It is likely that malloc(0) returning a valid pointer is a bug > > |> that has prevented this problem from being observed. > > > > It's not a bug, it's a behaviour explicitly allowed by the C standard. > > > > The bug is in xmalloc, meaning that it assumes that returning NULL is > always an error. Presumably xmalloc should look *either* like: > > void *xmalloc(size_t s) > { > void *p = malloc(s); > > if ( !p && s ) > barf(); > else > return p; > } > > ... or ... > > void *xmalloc(size_t s) > { > void *p; > > /* Always return a valid allocation */ > if ( s == 0 ) s = 1; > p = malloc(s); > > if ( !p ) > barf(); > else > return p; > } You are correct that the bug is in xmalloc(). However, I think the true bug is that xmalloc() exists! Malloc should be called directly and any special cases for that specific call should be handled at that time. Cheers, Dick Johnson Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/