public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: modutils-2.3.15 'insmod'
Date: 9 Jul 2003 15:44:42 -0700	[thread overview]
Message-ID: <bei5sq$9ba$1@cesium.transmeta.com> (raw)
In-Reply-To: jer84zln59.fsf@sykes.suse.de

Followup to:  <jer84zln59.fsf@sykes.suse.de>
By author:    Andreas Schwab <schwab@suse.de>
In newsgroup: linux.dev.kernel
>
> "Richard B. Johnson" <root@chaos.analogic.com> 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;
}
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64

  parent reply	other threads:[~2003-07-09 22:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-09 15:25 modutils-2.3.15 'insmod' Richard B. Johnson
2003-07-09 15:45 ` Andreas Schwab
2003-07-09 16:04   ` Bill Rugolsky Jr.
2003-07-09 22:44   ` H. Peter Anvin [this message]
2003-07-09 23:51     ` Richard B. Johnson
2003-07-09 16:08 ` Kurt Wall
2003-07-09 16:33   ` Andy Isaacson
2003-07-14 11:41 ` Keith Owens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='bei5sq$9ba$1@cesium.transmeta.com' \
    --to=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox