[PATCH] ldtoa: Fix insufficient valid output digits for "%f" format.
Takashi Yano
takashi.yano@nifty.ne.jp
Thu Nov 25 21:51:06 GMT 2021
On Thu, 25 Nov 2021 15:09:33 +0100
Corinna Vinschen wrote:
> 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 for checking. I have just submitted v2 patch fixed.
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Newlib
mailing list