-lmalloc

Mark Moraes moraes at csri.toronto.edu
Wed Feb 1 13:10:58 AEST 1989


In article <3724 at ingr.com> dan at ingr.com (Dan Webb) writes:
>> But there is also something strange with -lmalloc.  Sometimes,
>> programs which execute perfectly with the bsd malloc, core dump when
>> the other malloc is invoked.  For example, using X lib with bsd malloc
>> is ok, but with lmalloc core dumps occur.
>

Specifically for X lib, edit lib/X/Xlibos.h to define MALLOC_0_RETURNS_NULL
Grumble, grumble - see below.

>I probably don't have to convince too many people of this, but a request
>for zero bytes is by no means an invalid request.  I think -lmalloc should
>be fixed.

NOOOOO. PLEASE. malloc(0) SHOULD returns a NULL pointer and set EINVAL.
malloc(0) IS an invalid request if you stop and think about it for a
moment.

If you ask for 0 bytes (count 'em - zero), you presumably mean that
you don't want ANY storage. i.e. any pointer you get back is equally
valid because you aren't going to dereference it - EVER. If you
dereference it, then you should have used malloc(1), or
malloc(sizeof(whatever))

We have a debugging malloc here that botches an assertion and dumps
core if you call malloc(0) - finds lots of interesting bugs. Malloc(0)
is a bug, IMHO! Tell the people whose programs dump core with
malloc(0) to fix them. There are far too many backward compatible bugs
in the libraries already (can you say realloc(a freed block)?)

I'd be very interested in hearing your reasons why you feel malloc(0)
should return a pointer to valid storage. How many bytes of storage
you want for malloc(0)?

Reply by e-mail please - I'll summarize if there's enough response.




More information about the Comp.sys.sgi mailing list