From 64f62c47e9c350f353336f2df6714e1d48ec50d8 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 4 Sep 2024 13:21:23 +0000 Subject: Do not set errno for overflowing NaN payload in strtod/nan (bug 32045) As reported in bug 32045, it's incorrect for strtod/nan functions to set errno based on overflowing payload (strtod should only set errno for overflow / underflow of its actual result, and potentially if nothing in the string can be parsed as a number at all; nan should be a pure function that never sets it). Save and restore errno around the internal strtoull call and add associated test coverage. Tested for x86_64. --- stdlib/strtod_nan_main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'stdlib') diff --git a/stdlib/strtod_nan_main.c b/stdlib/strtod_nan_main.c index 4cb286d2b3..39fb7e9f75 100644 --- a/stdlib/strtod_nan_main.c +++ b/stdlib/strtod_nan_main.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -50,7 +51,9 @@ STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc) STRING_TYPE *endp; unsigned long long int mant; + int save_errno = errno; mant = STRTOULL (str, &endp, 0); + __set_errno (save_errno); if (endp == cp) SET_NAN_PAYLOAD (retval, mant); -- cgit v1.2.3