diff options
author | Bruno Haible <bruno@clisp.org> | 2007-02-25 21:17:11 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2007-02-25 21:17:11 +0000 |
commit | a7b66f7ce60806e824c73ae8dd97b3316ca880c0 (patch) | |
tree | d46bd5b34fe83615a31e68f08fdb7c8fc2c6692e | |
parent | c4dcbfedc7468a2d820ffa82e656eaf75b159c0e (diff) | |
download | gnulib-a7b66f7ce60806e824c73ae8dd97b3316ca880c0.tar.gz |
Fix estimate of size needed for a 'a' or 'A' conversion.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/vasnprintf.c | 22 |
2 files changed, 26 insertions, 1 deletions
@@ -1,5 +1,10 @@ 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. (Files): Replace lib/pathname.h with lib/filename.h. Replace lib/concatpath.c with lib/concat-filename.c. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 67406ae860..33e90d53ab 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -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) |