Fix estimate of size needed for a 'a' or 'A' conversion.
authorBruno Haible <bruno@clisp.org>
Sun, 25 Feb 2007 21:17:11 +0000 (21:17 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 25 Feb 2007 21:17:11 +0000 (21:17 +0000)
ChangeLog
lib/vasnprintf.c

index b446a46a268b288580cbe84ae70525caf6c71682..6fc9effd711dc9e49c0f58c1767b6dc172c69ca5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-02-25  Bruno Haible  <bruno@clisp.org>
+
+       * lib/vasnprintf.c (VASNPRINTF): Fix estimate of size needed for a
+       'a' or 'A' conversion.
+
 2007-02-25  Bruno Haible  <bruno@clisp.org>
 
        * modules/filename: Renamed from modules/pathname.
index 67406ae860c92ae5129973cd622e153cb9476c2c..33e90d53abf12525960f30f73fd8e6c1a637772d 100644 (file)
@@ -430,12 +430,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)