Re: modutils-2.3.15 'insmod'

From: H. Peter Anvin (hpa@zytor.com)
Date: Wed Jul 09 2003 - 17:44:42 EST


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
-
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:32 EST