aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2024-09-04 13:21:23 +0000
committerJoseph Myers <josmyers@redhat.com>2024-09-04 13:21:23 +0000
commit64f62c47e9c350f353336f2df6714e1d48ec50d8 (patch)
tree57bfdaafa1d6340bbe78956f4a2fe71d0f5479f6 /stdlib
parentbe77d5ae417236883c02d3d67c0716e3f669fa41 (diff)
downloadglibc-64f62c47e9c350f353336f2df6714e1d48ec50d8.tar.xz
glibc-64f62c47e9c350f353336f2df6714e1d48ec50d8.zip
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.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/strtod_nan_main.c3
1 files changed, 3 insertions, 0 deletions
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
<https://www.gnu.org/licenses/>. */
+#include <errno.h>
#include <ieee754.h>
#include <locale.h>
#include <math.h>
@@ -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);