summaryrefslogtreecommitdiffstats
path: root/gettext-runtime
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2006-08-28 16:07:20 +0000
committerBruno Haible <bruno@clisp.org>2009-06-23 12:13:57 +0200
commitb868019c4581f7f98082912d32a491b19ab6036b (patch)
treecc1a5746ffcb92cbba9429efdb7059aff0085afc /gettext-runtime
parent37764874e146ca44797d9b98a9d895a3456b162e (diff)
downloadexternal_gettext-b868019c4581f7f98082912d32a491b19ab6036b.zip
external_gettext-b868019c4581f7f98082912d32a491b19ab6036b.tar.gz
external_gettext-b868019c4581f7f98082912d32a491b19ab6036b.tar.bz2
Move the INT_MAX check to where a size_t -> int cast occurs.
Diffstat (limited to 'gettext-runtime')
-rw-r--r--gettext-runtime/libasprintf/ChangeLog8
-rw-r--r--gettext-runtime/libasprintf/vasnprintf.c22
-rw-r--r--gettext-runtime/libasprintf/vasprintf.c20
3 files changed, 29 insertions, 21 deletions
diff --git a/gettext-runtime/libasprintf/ChangeLog b/gettext-runtime/libasprintf/ChangeLog
index 84f533a..1a9ab28 100644
--- a/gettext-runtime/libasprintf/ChangeLog
+++ b/gettext-runtime/libasprintf/ChangeLog
@@ -1,3 +1,11 @@
+2006-08-26 Bruno Haible <bruno@clisp.org>
+
+ * vasnprintf.c (EOVERFLOW): Remove definition.
+ (VASNPRINTF): Return a string of length > INT_MAX without failing.
+ * vasprintf.c: Include errno.h, limits.h.
+ (EOVERFLOW): New fallback definition.
+ (vasprintf): Test here whether the string length is > INT_MAX.
+
2006-08-28 Bruno Haible <bruno@clisp.org>
* configure.ac: Remove bh_C_SIGNED invocation.
diff --git a/gettext-runtime/libasprintf/vasnprintf.c b/gettext-runtime/libasprintf/vasnprintf.c
index cef29a7..08a4783 100644
--- a/gettext-runtime/libasprintf/vasnprintf.c
+++ b/gettext-runtime/libasprintf/vasnprintf.c
@@ -41,7 +41,7 @@
#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
#include <string.h> /* memcpy(), strlen() */
#include <errno.h> /* errno */
-#include <limits.h> /* CHAR_BIT, INT_MAX */
+#include <limits.h> /* CHAR_BIT */
#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
#if WIDE_CHAR_VERSION
# include "wprintf-parse.h"
@@ -52,11 +52,6 @@
/* Checked size_t computations. */
#include "xsize.h"
-/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */
-#ifndef EOVERFLOW
-# define EOVERFLOW E2BIG
-#endif
-
#ifdef HAVE_WCHAR_T
# ifdef HAVE_WCSLEN
# define local_wcslen wcslen
@@ -870,19 +865,12 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
free (buf_malloced);
CLEANUP ();
*lengthp = length;
- if (length > INT_MAX)
- goto length_overflow;
+ /* Note that we can produce a big string of a length > INT_MAX. POSIX
+ says that snprintf() fails with errno = EOVERFLOW in this case, but
+ that's only because snprintf() returns an 'int'. This function does
+ not have this limitation. */
return result;
- length_overflow:
- /* We could produce such a big string, but its length doesn't fit into
- an 'int'. POSIX says that snprintf() fails with errno = EOVERFLOW in
- this case. */
- if (result != resultbuf)
- free (result);
- errno = EOVERFLOW;
- return NULL;
-
out_of_memory:
if (!(result == resultbuf || result == NULL))
free (result);
diff --git a/gettext-runtime/libasprintf/vasprintf.c b/gettext-runtime/libasprintf/vasprintf.c
index 839073e..feb8b25 100644
--- a/gettext-runtime/libasprintf/vasprintf.c
+++ b/gettext-runtime/libasprintf/vasprintf.c
@@ -1,5 +1,5 @@
/* Formatted output to strings.
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@@ -23,10 +23,17 @@
/* Specification. */
#include "vasprintf.h"
+#include <errno.h>
+#include <limits.h>
#include <stdlib.h>
#include "vasnprintf.h"
+/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */
+#ifndef EOVERFLOW
+# define EOVERFLOW E2BIG
+#endif
+
int
vasprintf (char **resultp, const char *format, va_list args)
{
@@ -35,9 +42,14 @@ vasprintf (char **resultp, const char *format, va_list args)
if (result == NULL)
return -1;
+ if (length > INT_MAX)
+ {
+ free (result);
+ errno = EOVERFLOW;
+ return -1;
+ }
+
*resultp = result;
- /* Return the number of resulting bytes, excluding the trailing NUL.
- If it wouldn't fit in an 'int', vasnprintf() would have returned NULL
- and set errno to EOVERFLOW. */
+ /* Return the number of resulting bytes, excluding the trailing NUL. */
return length;
}