From: Bruno Haible Date: Sat, 22 Jun 2024 10:17:10 +0000 (+0200) Subject: vasprintf: Make return convention consistent with other modules. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=134cfb88c06b0a427f3b4c60acb664c9cc5ec2d9;p=gnulib.git vasprintf: Make return convention consistent with other modules. * lib/vasprintf.c: Include . (vasprintf): If the length is > PTRDIFF_MAX, fail with ENOMEM, not EOVERFLOW. * modules/vasprintf (Depends-on): Add stdint. --- diff --git a/ChangeLog b/ChangeLog index b38ebee8a3..7c720ba885 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2024-06-22 Bruno Haible + vasprintf: Make return convention consistent with other modules. + * lib/vasprintf.c: Include . + (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. diff --git a/lib/vasprintf.c b/lib/vasprintf.c index e52aaca586..757d1c740a 100644 --- a/lib/vasprintf.c +++ b/lib/vasprintf.c @@ -25,6 +25,7 @@ #include #include +#include #include #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. */ diff --git a/modules/vasprintf b/modules/vasprintf index 91d082bd27..46bfcc51ba 100644 --- a/modules/vasprintf +++ b/modules/vasprintf @@ -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