out of memory while allocating 0 bytes

Dmitri dmitri@users.sourceforge.net
Sun Sep 15 12:04:02 2002


--=-Zjq15t1Kr5pGI1wEXiMo
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Sun, 2002-09-15 at 02:45, Werner Koch wrote:

> On Sun, 15 Sep 2002 03:13:41 +0900 (JST), Yamagata Yoriyuki said:
>=20
> > when m_alloc is called with the argument n =3D 0.  Since malloc in this
> > system returns NULL for the request of 0-byte allocation, this causes
>=20
> This is known.  The quick fix is to change it in util/memory.c:
>=20
> void *
> FNAME(alloc)( size_t n FNAMEPRT )
> ...
>   #else
>     /* mallocing zero bytes is undefined by ISO-C, so we better make
>        sure that it won't happen */
>     if (!n)
>       n =3D 1;
>     if( !(p =3D malloc( n )) )
> 	out_of_core(n,0);

Quite often another, smaller, workaround is used:

    if( !(p =3D malloc( n+1 )) )
	out_of_core(n,0);

Dmitri


--=-Zjq15t1Kr5pGI1wEXiMo
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQA9hFtHXksyLpO6T4IRAqVkAJ4wy4oRcces5Psr2wOgoOn8Ec0YCwCfQS0i
AJdd6I+7fLy7Cajf+Zr7cgA=
=r53j
-----END PGP SIGNATURE-----

--=-Zjq15t1Kr5pGI1wEXiMo--