Subject: Re: Problems with 2006Q3
To: None <pkgsrc-users@netbsd.org>
From: Hrvoje =?utf-8?q?Habjani=C4=87?= <hrvoje.habjanic@zg.t-com.hr>
List: pkgsrc-users
Date: 11/03/2006 10:31:15
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.

=46rom 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 memo=
ry
  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 followi=
ng=20
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 requi=
res=20
that malloc(0) returns something other than NULL, then patch should be in p=
ng=20
package, i guess.

H.