Debugging help needed ...

Nick Burrett nick at dsvr.net
Mon Sep 1 00:58:31 PDT 2003


Stefan Bellon wrote:
> I wrote:
> 
>>xmalloc() looks like this and I don't see any obvious mistakes:
>>
>>void *
>>xmalloc(size_t size){
>>    void *ptr;
>>    ptr = malloc(size);
>>    if (ptr == NULL && size == 0)
>>        ptr = malloc(1);
>>    if (ptr == NULL) {
>>        xmem_error("xmalloc"); 
>>    }
>>    return ptr;
>>}
> 
> 
> There indeed seems to be a problem with this code and the UnixLib
> implementation of malloc().
> 
> If I rewrite it to read as follows, then bogofilter works and does
> neither lock-up the machine nor crash with a stack backtrace (tried
> application space so far, will try Dynamic Area next, but I hope that
> doesn't make a difference here):
> 
> void *
> xmalloc(size_t size){
>     void *ptr;
>     if (size == 0)
>         size = 1;
>     ptr = malloc(size);
>     if (ptr == NULL) {
>         xmem_error("xmalloc"); 
>     }
>     return ptr;
> }
> 
> So, it looks like UnixLib doesn't like malloc(0). However,
> unixlib/source/alloc.c states that allocating zero should be possible
> as well (it's however difficult to see whether this is a comment meant
> to apply for RISC OS as well).

I think the problem is elsewhere otherwise we'd have seen this bug years 
ago.

Are you using the 2.95 compiler or the 3.3 compiler ?

Nick.



-- 
Nick Burrett
Network Engineer, Designer Servers Ltd.   http://www.dsvr.co.uk




More information about the gcc mailing list