]> Savannah Git Hosting - gnulib.git/commitdiff
vasprintf: Make return convention consistent with other modules.
authorBruno Haible <bruno@clisp.org>
Sat, 22 Jun 2024 10:17:10 +0000 (12:17 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 22 Jun 2024 10:17:44 +0000 (12:17 +0200)
* lib/vasprintf.c: Include <stdint.h>.
(vasprintf): If the length is > PTRDIFF_MAX, fail with ENOMEM, not
EOVERFLOW.
* modules/vasprintf (Depends-on): Add stdint.

ChangeLog
lib/vasprintf.c
modules/vasprintf

index b38ebee8a35e9aef8b193df0391a63fd268c9daa..7c720ba88590ec00713346be4b4f848f54d0cc3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2024-06-22  Bruno Haible  <bruno@clisp.org>
 
+       vasprintf: Make return convention consistent with other modules.
+       * lib/vasprintf.c: Include <stdint.h>.
+       (vasprintf): If the length is > PTRDIFF_MAX, fail with ENOMEM, not
+       EOVERFLOW.
+       * modules/vasprintf (Depends-on): Add stdint.
+
        vazsprintf: New module.
        * lib/stdio.in.h (azsprintf, vazsprintf): New declarations.
        * lib/vazsprintf.c: New file, based on lib/vasprintf.c.
index e52aaca5864ad30105aa4adef9b2fdba8bab5294..757d1c740a8b8ed98bd6b432a0e5fee64b18fe91 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <errno.h>
 #include <limits.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "vasnprintf.h"
@@ -37,12 +38,21 @@ vasprintf (char **resultp, const char *format, va_list args)
   if (result == NULL)
     return -1;
 
+#if PTRDIFF_MAX > INT_MAX
   if (length > INT_MAX)
     {
       free (result);
-      errno = EOVERFLOW;
+      errno = (length > PTRDIFF_MAX ? ENOMEM : EOVERFLOW);
       return -1;
     }
+#else
+  if (length > PTRDIFF_MAX)
+    {
+      free (result);
+      errno = ENOMEM;
+      return -1;
+    }
+#endif
 
   *resultp = result;
   /* Return the number of resulting bytes, excluding the trailing NUL.  */
index 91d082bd271a3c9023b604a2b5a8802c12f9c694..46bfcc51ba3e0bf11a1a458f813fc8ff1cf88f22 100644 (file)
@@ -11,6 +11,7 @@ stdio
 extensions
 vasnprintf      [test $HAVE_VASPRINTF = 0 || test $REPLACE_VASPRINTF = 1]
 errno           [test $HAVE_VASPRINTF = 0 || test $REPLACE_VASPRINTF = 1]
+stdint          [test $HAVE_VASPRINTF = 0 || test $REPLACE_VASPRINTF = 1]
 
 configure.ac:
 gl_FUNC_VASPRINTF