From 763c993419a6d59e6d2e1d7d60bc8d23981b5a94 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 28 Nov 2023 23:22:58 +0100 Subject: [PATCH] string: resolve testsuite failure with aarch64 Fixes: v4.17-9-g323210d --- src/string.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/string.c b/src/string.c index 11f3c9f..8e12b4a 100644 --- a/src/string.c +++ b/src/string.c @@ -1030,8 +1030,19 @@ EXPORT_SYMBOL unsigned long long HX_strtoull_unit(const char *s, errno = ERANGE; return ULLONG_MAX; } + /* + * https://eel.is/c++draft/conv.double#2: values + * unrepresentable in the target type (such as forcing -5.2f + * into a uint) is UB. Thus check for range and apply the + * negation after the conversion to ULL. + */ + if (q > ULLONG_MAX) { + errno = ERANGE; + return ULLONG_MAX; + } + unsigned long long r = q; errno = 0; - return neg ? -q : q; + return neg ? -r : r; } if (exponent == 0) exponent = 1000; -- 2.43.0