From 23787fc71a9179e991c1bbeb0ca8f6448491d14f Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Sun, 17 Nov 2024 16:23:01 +0100 Subject: [PATCH] fix #276: parse_infnan handles FASTFLOAT_ALLOWS_LEADING_PLUS correctly --- CONTRIBUTORS | 1 + include/fast_float/parse_number.h | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index da1e5d6..4b70555 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -8,3 +8,4 @@ Lénárd Szolnoki Jan Pharago Maya Warrier Taha Khokhar +Anders Dalvander diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 5699bba..8b9fb85 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -25,18 +25,15 @@ from_chars_result_t FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first, from_chars_result_t answer{}; answer.ptr = first; answer.ec = std::errc(); // be optimistic - bool minusSign = false; - if (*first == - UC('-')) { // assume first < last, so dereference without checks; - // C++17 20.19.3.(7.1) explicitly forbids '+' here - minusSign = true; - ++first; - } + bool const minusSign = (*first == UC('-')); // assume first < last, so dereference without checks; #ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if (*first == UC('+')) { + if ((*first == UC('-')) || (*first == UC('+'))) { +#else + // C++17 20.19.3.(7.1) explicitly forbids '+' sign here + if (*first == UC('-')) { +#endif ++first; } -#endif if (last - first >= 3) { if (fastfloat_strncasecmp(first, str_const_nan(), 3)) { answer.ptr = (first += 3);