|
Re: Re: fressh-0.3 works on mipsel. Thanks!: msg#00140lib.uclibc.general
On Mon Sep 30, 2002 at 12:27:31PM +0100, Matthew Bloch wrote: > Here we go, try compiling this program under uClibc and glibc: First, my appologies for not seeing this email sooner. I just realized that I never replied. > ------------------------------- realloc0.c --------------------------------- > #include <stdlib.h> > > int main(int argc, char **argv) > { > void *ptr = NULL; > ptr = realloc(ptr, 0); > printf("pointer = %p\n", ptr); > return 0; > } > ---------------------------------------------------------------------------- > > glibc prints a valid pointer, uClibc prints (nil). I suggest that this is a > uClibc bug because glibc's behaviour is explicit in that "If you pass a null > pointer for PTR, `realloc' behaves just like `malloc (NEWSIZE)'". uClibc > will happily return a valid pointer for malloc(0) but realloc(NULL, 0) does > not behave the same way. Not true. Regardless of whether uClibc is compiled to include "malloc-930716" or "malloc", calling malloc(0) returns a NULL. > Also I only found this bug in uClibc after fixing a bug in the fressh buffer > allocation routine which relied on an uninitialised pointer being zero; > updated complete patch attached. Here's the deal. According to SuSv3: http://www.opengroup.org/onlinepubs/007904975/functions/realloc.html If ptr is a null pointer, realloc() shall be equivalent to malloc() for the specified size. http://www.opengroup.org/onlinepubs/007904975/functions/malloc.html If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer. So yes, there is a behavior difference between glibc and uClibc. This is a legitimate, since the standards specify this case to be implementation-defined. Glibc returns a live pointer (pointing to some live storage space), which IMHO is terribly stupid and enables poor programming since people may actually try and _use_ that pointer, and they may actually succeed. uClibc returns a NULL, which guarantees a richly deserved segfault if someone uses the NULL pointer. -Erik -- Erik B. Andersen http://codepoet-consulting.com/ --This message was written using 73% post-consumer electrons-- |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: enabling malloc `uClinux broken munmap' code: 00140, Erik Andersen |
|---|---|
| Next by Date: | Re: Compile Openshh with the uClibc error: 00140, Erik Andersen |
| Previous by Thread: | TinyLogini: 00140, Jean-marc Harang |
| Next by Thread: | Re: Compile Openshh with the uClibc error: 00140, Erik Andersen |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |