bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glibc's snprintf can fail with ENOMEM: replacement needed


From: Bruno Haible
Subject: Re: glibc's snprintf can fail with ENOMEM: replacement needed
Date: Fri, 11 Apr 2008 15:45:01 +0200
User-agent: KMail/1.5.4

Eric Blake wrote:
> According to Bruno Haible on 4/11/2008 4:43 AM:
> |   1) for float to decimal conversion, think of snprintf (NULL, "%Le", x)
> |      or snprintf (NULL, "%Lf", x)
> |
> | At least in the first case, I don't see how the number of output bytes could
> | be determined without doing the actual conversion.
> 
> True, but in the first case, the maximum number of significant digits is
> known in advance, so you can still use a fixed-size stack-allocated buffer
> to do the work.

It also depends on the exponent. And with 'long double's you can have up to
32-bit exponents. In order to determine how
   9.9999999999999999999999999999999999999999999e+3000000
rounds you need memory of size  3000000*log(10)/(8*log(2)). The only way to
allocate such an amount of memory inside snprintf is through malloc.

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]