diff options
author | Joe Ramsay <Joe.Ramsay@arm.com> | 2024-02-13 16:21:56 +0000 |
---|---|---|
committer | Joe Ramsay <joe.ramsay@arm.com> | 2024-02-13 16:21:56 +0000 |
commit | b2287abf708f8bbecb7a3b26b0391c8146c912ac (patch) | |
tree | 7e73cf3fcc39d14c6df952355f1e80a00af3329f | |
parent | 7816cea3748517e5243637faa8cbc73c408e1bc4 (diff) | |
download | arm-optimized-routines-b2287abf708f8bbecb7a3b26b0391c8146c912ac.tar.gz |
math/test: Reject invalid intervals in ULP tool
Intervals which cannot be parsed are now reported as errors.
-rw-r--r-- | math/test/ulp.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/math/test/ulp.c b/math/test/ulp.c index 5ff2997..22ac6fe 100644 --- a/math/test/ulp.c +++ b/math/test/ulp.c @@ -1,7 +1,7 @@ /* * ULP error checking tool for math functions. * - * Copyright (c) 2019-2023, Arm Limited. + * Copyright (c) 2019-2024, Arm Limited. * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception */ @@ -633,9 +633,21 @@ getnum (const char *s, int singleprec) sign = singleprec ? 1ULL << 31 : 1ULL << 63; s++; } + + /* Sentinel value for failed parse. */ + char *should_not_be_s = NULL; + /* 0xXXXX is treated as bit representation, '-' flips the sign bit. */ if (s[0] == '0' && tolower (s[1]) == 'x' && strchr (s, 'p') == 0) - return sign ^ strtoull (s, 0, 0); + { + uint64_t out = sign ^ strtoull (s, &should_not_be_s, 0); + if (should_not_be_s == s) + { + printf ("ERROR: Could not parse '%s'\n", s); + exit (1); + } + return out; + } // /* SNaN, QNaN, NaN, Inf. */ // for (i=0; s[i] && i < sizeof buf; i++) // buf[i] = tolower(s[i]); @@ -647,8 +659,16 @@ getnum (const char *s, int singleprec) // if (strcmp(buf, "inf") == 0 || strcmp(buf, "infinity") == 0) // return sign | (singleprec ? 0x7f800000 : 0x7ff0000000000000); /* Otherwise assume it's a floating-point literal. */ - return sign - | (singleprec ? asuint (strtof (s, 0)) : asuint64 (strtod (s, 0))); + uint64_t out = sign + | (singleprec ? asuint (strtof (s, &should_not_be_s)) + : asuint64 (strtod (s, &should_not_be_s))); + if (should_not_be_s == s) + { + printf ("ERROR: Could not parse '%s'\n", s); + exit (1); + } + + return out; } static void |