Skip to content

Commit 166d83b

Browse files
committed
[CRT] Fix cvt to not overflow the buffer on NAN/INF
Fixes crash in msvcrt_winetest printf
1 parent 4a63e19 commit 166d83b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sdk/lib/crt/stdlib/fcvtbuf.c

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int
4848
double fi, fj;
4949
char *p, *p1;
5050

51+
if (_isnan(arg))
52+
{
53+
snprintf(buf, ndigits, "1.#QNAN");
54+
*decpt = 0;
55+
*sign = 0;
56+
return buf;
57+
}
58+
if (!_finite(arg))
59+
{
60+
snprintf(buf, ndigits, "1.#INF");
61+
*decpt = 0;
62+
*sign = 0;
63+
return buf;
64+
}
65+
5166
if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
5267
r2 = 0;
5368
*sign = 0;

0 commit comments

Comments
 (0)