aboutsummaryrefslogtreecommitdiff
path: root/libidn
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2005-03-15 22:31:32 +0000
committerRoland McGrath <roland@gnu.org>2005-03-15 22:31:32 +0000
commitfdc07525f4c210ab6a394ce52955dbf279fff311 (patch)
tree2dd60fb60cc9d9619445aea21c012c62e2edc3ca /libidn
parent3b7289d409e5575d816a0b8d2cb0fb30949c5e2b (diff)
downloadglibc-fdc07525f4c210ab6a394ce52955dbf279fff311.tar
glibc-fdc07525f4c210ab6a394ce52955dbf279fff311.tar.gz
glibc-fdc07525f4c210ab6a394ce52955dbf279fff311.tar.bz2
glibc-fdc07525f4c210ab6a394ce52955dbf279fff311.zip
[BZ #789]
2005-03-15 Jakub Jelinek <jakub@redhat.com> [BZ #789] * sysdeps/i386/i686/hp-timing.h (HP_TIMING_ACCUM): Fix asm constraints. Remove memory clobber. * sysdeps/x86_64/hp-timing.h (HP_TIMING_ACCUM): Make the addition thread-safe. Subtract GLRO(dl_hp_timing_overhead) from Diff.
Diffstat (limited to 'libidn')
-rw-r--r--libidn/iconvme.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/libidn/iconvme.c b/libidn/iconvme.c
index daf0c8e349..cc4dd1daa5 100644
--- a/libidn/iconvme.c
+++ b/libidn/iconvme.c
@@ -41,10 +41,14 @@
#if HAVE_ICONV
/* Get iconv etc. */
# include <iconv.h>
-/* Get MB_LEN_MAX. */
+/* Get MB_LEN_MAX, CHAR_BIT. */
# include <limits.h>
#endif
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
/* Convert a zero-terminated string STR from the FROM_CODSET code set
to the TO_CODESET code set. The returned string is allocated using
malloc, and must be dellocated by the caller using free. On
@@ -63,10 +67,18 @@ iconv_string (const char *str, const char *from_codeset,
char *p = (char *) str;
size_t inbytes_remaining = strlen (p);
/* Guess the maximum length the output string can have. */
- size_t outbuf_size = (inbytes_remaining + 1) * MB_LEN_MAX;
- size_t outbytes_remaining = outbuf_size - 1; /* -1 for NUL */
+ size_t outbuf_size = inbytes_remaining + 1;
+ size_t outbytes_remaining;
size_t err;
int have_error = 0;
+
+ /* Use a worst-case output size guess, so long as that wouldn't be
+ too large for comfort. It's OK if the guess is wrong so long as
+ it's nonzero. */
+ size_t approx_sqrt_SIZE_MAX = SIZE_MAX >> (sizeof (size_t) * CHAR_BIT / 2);
+ if (outbuf_size <= approx_sqrt_SIZE_MAX / MB_LEN_MAX)
+ outbuf_size *= MB_LEN_MAX;
+ outbytes_remaining = outbuf_size - 1;
#endif
if (strcmp (to_codeset, from_codeset) == 0)