This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: snprintf allocates memory?!?
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jim Meyering <jim at meyering dot net>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 10 Apr 2008 22:28:04 +0200
- Subject: Re: snprintf allocates memory?!?
- References: <87fxttpiup.fsf@rho.meyering.net>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 10, 2008 at 10:15:10PM +0200, Jim Meyering wrote:
> There is a surprising bug in glibc's snprintf:
> it can _allocate memory_ (and an arbitrarily large amount)
> even for a tiny buffer. Just filed as BZ 441945.
> Obviously, snprintf should never need to call malloc.
Why?
POSIX says:
Implementations may support additional errors not included in this list, may
generate errors included in this list under circumstances other than those
described here, or may contain extensions or limitations that prevent some
errors from occurring. The ERRORS section on each reference page specifies
whether an error shall be returned, or whether it may be returned.
Implementations shall not generate a different error number from the ones
described here for error conditions described in this volume of IEEE Std
1003.1-2001, but may generate additional errors unless explicitly disallowed
for a particular function.
and I certainly don't see anything explicitly disallowing ENOMEM for
snprintf.
Jakub