Re: modutils-2.3.15 'insmod'

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Wed Jul 09 2003 - 18:51:01 EST


On Wed, 9 Jul 2003, H. Peter Anvin wrote:

> 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;
> }

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/



This archive was generated by hypermail 2b29 : Tue Jul 15 2003 - 22:00:33 EST