[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] vasprintf proposed fix for int overflow check
From: |
Bruno Haible |
Subject: |
Re: [Bug-gnulib] vasprintf proposed fix for int overflow check |
Date: |
Thu, 30 Oct 2003 22:51:31 +0100 |
User-agent: |
KMail/1.5 |
Paul Eggert wrote:
> Shouldn't asprintf and vasprintf be consistent with snprintf?
> snprintf is defined by POSIX to set errno to EOVERFLOW in this case.
It's just that the other implementations of asprintf() and vasprintf()
currently don't do it like this.
- glibc's libio/vasprintf.c has this code:
ret = INTUSE(_IO_vfprintf) (&sf._sbf._f, format, args);
if (ret < 0)
{
free (sf._sbf._f._IO_buf_base);
return ret;
}
i.e. it does not guarantee an errno (since free() can kill errno).
- *BSD's documentation http://www.chedong.com/phpMan.php/man/asprintf/3
doesn't mention errno, and its code
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdio/asprintf.c?rev=1.13&content-type=text/plain
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdio/vasprintf.c?rev=1.18&content-type=text/plain
always sets errno to ENOMEM in case of any failure.
> Perhaps glibc's documentation and behavior need to be changed to
> reflect this; but let's start with gnulib.
Well, I think it's better to start with glibc, since it's harder to convince
Ulrich than me :-)
> I looked into EOVERFLOW a bit more, and the usual practice in gnulib
> (e.g. poll.c, c-stack.c) is to substitute EINVAL for EOVERFLOW if
> EOVERFLOW is not available. So, how about this further patch?
Looks good. I propose to commit it when we get green light on the glibc
side as well.
Bruno