]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix estimate of size needed for a 'a' or 'A' conversion.
authorBruno Haible <bruno@clisp.org>
Sun, 25 Feb 2007 21:16:09 +0000 (21:16 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:41 +0000 (12:14 +0200)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/vasnprintf.c
gettext-runtime/libasprintf/ChangeLog
gettext-runtime/libasprintf/vasnprintf.c

index a5d501845a0fc63a6695bba69681b8d633b37a8c..a0281a76597307b2ec7ca79c5cca84fce8d7fad9 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-25  Bruno Haible  <bruno@clisp.org>
+
+       * vasnprintf.c (VASNPRINTF): Fix estimate of size needed for a 'a' or
+       'A' conversion.
+
 2007-01-29  Bruno Haible  <bruno@clisp.org>
 
        * printf-args.h: Use '#if HAVE_*' instead of '#ifdef HAVE_*'.
index 48cac1b3ca3ed2fc689385df648ea0ef2c5c13f4..fbc2d743d6116faf4789fab94da6b84fc6639a3a 100644 (file)
@@ -431,12 +431,32 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
                      break;
 
                    case 'e': case 'E': case 'g': case 'G':
-                   case 'a': case 'A':
                      tmp_length =
                        12; /* sign, decimal point, exponent etc. */
                      tmp_length = xsum (tmp_length, precision);
                      break;
 
+                   case 'a': case 'A':
+# if HAVE_LONG_DOUBLE
+                     if (type == TYPE_LONGDOUBLE)
+                       tmp_length =
+                         (unsigned int) (LDBL_DIG
+                                         * 0.831 /* decimal -> hexadecimal */
+                                        )
+                         + 1; /* turn floor into ceil */
+                     else
+# endif
+                       tmp_length =
+                         (unsigned int) (DBL_DIG
+                                         * 0.831 /* decimal -> hexadecimal */
+                                        )
+                         + 1; /* turn floor into ceil */
+                     if (tmp_length < precision)
+                       tmp_length = precision;
+                     /* Account for sign, decimal point etc. */
+                     tmp_length = xsum (tmp_length, 12);
+                     break;
+
                    case 'c':
 # if HAVE_WINT_T && !WIDE_CHAR_VERSION
                      if (type == TYPE_WIDE_CHAR)
index 7b886769aeb400fa5fc879c387d719238a4bbfca..6af8ceb33702a4125aa5d74a7001287ba870bb18 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-25  Bruno Haible  <bruno@clisp.org>
+
+       * vasnprintf.c (VASNPRINTF): Fix estimate of size needed for a 'a' or
+       'A' conversion.
+
 2007-01-29  Bruno Haible  <bruno@clisp.org>
 
        * printf-args.h: Use '#if HAVE_*' instead of '#ifdef HAVE_*'.
index 48cac1b3ca3ed2fc689385df648ea0ef2c5c13f4..fbc2d743d6116faf4789fab94da6b84fc6639a3a 100644 (file)
@@ -431,12 +431,32 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
                      break;
 
                    case 'e': case 'E': case 'g': case 'G':
-                   case 'a': case 'A':
                      tmp_length =
                        12; /* sign, decimal point, exponent etc. */
                      tmp_length = xsum (tmp_length, precision);
                      break;
 
+                   case 'a': case 'A':
+# if HAVE_LONG_DOUBLE
+                     if (type == TYPE_LONGDOUBLE)
+                       tmp_length =
+                         (unsigned int) (LDBL_DIG
+                                         * 0.831 /* decimal -> hexadecimal */
+                                        )
+                         + 1; /* turn floor into ceil */
+                     else
+# endif
+                       tmp_length =
+                         (unsigned int) (DBL_DIG
+                                         * 0.831 /* decimal -> hexadecimal */
+                                        )
+                         + 1; /* turn floor into ceil */
+                     if (tmp_length < precision)
+                       tmp_length = precision;
+                     /* Account for sign, decimal point etc. */
+                     tmp_length = xsum (tmp_length, 12);
+                     break;
+
                    case 'c':
 # if HAVE_WINT_T && !WIDE_CHAR_VERSION
                      if (type == TYPE_WIDE_CHAR)