[PATCH] ldtoa: Fix insufficient valid output digits for "%f" format.

Corinna Vinschen vinschen@redhat.com
Thu Nov 25 14:09:33 GMT 2021


Hi Takashi,

looks good, but I see a potential problem at one point:

On Nov 25 21:02, Takashi Yano wrote:
> +   limit now, either ndec (<= NDEC) or NDEC_SML, depending on ndigits. */
> +  int ndec;
> +  if (mode == 3) /* %f */
> +    {
> +      int expon = (e[NE - 1] & 0x7fff) - (EXONE - 1); /* exponent part */
> +      /* log2(10) approximately 485/146 */
> +      ndec = expon * 146 / 485 + ndigits;

We have targets with sizeof(int) == 2.  If expon is any number up to
0x7fff, multiplying it with 146 will overflow.  Using __int32_t for
expon should be safer.


Thanks,
Corinna



More information about the Newlib mailing list