[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: Paul Eggert
Subject: Re: [Bug-gnulib] vasprintf proposed fix for int overflow check
Date: 30 Oct 2003 11:04:10 -0800
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Bruno Haible <address@hidden> writes:

> Since asprintf() and vasprintf() are not specified to set errno in case
> of failure - neither in our vasprintf.h nor in glibc's documentation -
> you don't need to care about EOVERFLOW.

Shouldn't asprintf and vasprintf be consistent with snprintf?
snprintf is defined by POSIX to set errno to EOVERFLOW in this case.

Also, I don't see why vasprintf should leave errno undefined for this
particular failure.  vasprintf sets errno to a useful value in all
other failures; why should this case be different?  Code that invokes
vasprintf and asprintf should be able to diagnose errors properly.

Perhaps glibc's documentation and behavior need to be changed to
reflect this; but let's start with gnulib.

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?

2003-10-30  Paul Eggert  <address@hidden>

        * vasprintf.c: Include <errno.h>.
        (EOVERFLOW): Define to EINVAL if not defined.
        (vasprintf): Set errno to EOVERFLOW on integer overflow.

Index: vasprintf.c
RCS file: /cvsroot/gnulib/gnulib/lib/vasprintf.c,v
retrieving revision 1.3
diff -p -u -r1.3 vasprintf.c
--- vasprintf.c 30 Oct 2003 14:09:04 -0000      1.3
+++ vasprintf.c 30 Oct 2003 18:58:41 -0000
@@ -25,6 +25,11 @@
 #include <limits.h>
 #include <stdlib.h>
+#include <errno.h>
+#ifndef EOVERFLOW
 #include "vasnprintf.h"
@@ -39,6 +44,7 @@ vasprintf (char **resultp, const char *f
       /* We could produce such a big string, but can't return its length
         as an 'int'.  */
       free (result);
+      errno = EOVERFLOW;
       return -1;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]