pkgsrc-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Problems with 2006Q3
On Friday 03 November 2006 10:21, Tom Spindler wrote:
> > A free(3) which doesn't support being called with a NULL pointer is just
> > broken. What malloc does for size 0 is implementation defined.
> > Consistent with the spirit of the standard could be a wrapper which
> > turns allocations for 0 into allocations of 1, if a program depends on
> > that.
>
> To amplify this, IEEE 1003.1-2004 says for free():
> If ptr is a null pointer, no action shall occur.
> and for malloc():
> If size is 0, either a null pointer or a unique pointer that can
> be successfully passed to free() shall be returned.
From Tru64 man pages:
"
The malloc() function returns a pointer to a block of memory of at least
the number of bytes specified by the size parameter. The block is aligned
so that it can be used for any type of data, and the contents of the memory
are undefined. If the size parameter is 0 (zero), the malloc() function
returns a null pointer.
The free() function frees the block of memory pointed to by the pointer
parameter for further allocation. The block pointed to by the pointer
parameter must have been previously allocated as follows:
+ By either the malloc(), realloc(), or calloc() functions.
+ [XPG4-UNIX] By either the malloc(), realloc(), calloc(), or valloc()
functions.
"
They doesn't say what will happen when free(0) is called. Compiling following
program and executing it does work.
"
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Test\n");
free(0);
return(0);
}
"
# gcc -o pero test.c
# ./pero
Test
#
So, from Tru64 stand point free(malloc(0)) does work. If png specialy requires
that malloc(0) returns something other than NULL, then patch should be in png
package, i guess.
H.
Home |
Main Index |
Thread Index |
Old Index