Skip to content

Commit 23787fc

Browse files
committed
fix #276: parse_infnan handles FASTFLOAT_ALLOWS_LEADING_PLUS correctly
1 parent 72b2a73 commit 23787fc

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Lénárd Szolnoki
88
Jan Pharago
99
Maya Warrier
1010
Taha Khokhar
11+
Anders Dalvander

include/fast_float/parse_number.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ from_chars_result_t<UC> FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first,
2525
from_chars_result_t<UC> answer{};
2626
answer.ptr = first;
2727
answer.ec = std::errc(); // be optimistic
28-
bool minusSign = false;
29-
if (*first ==
30-
UC('-')) { // assume first < last, so dereference without checks;
31-
// C++17 20.19.3.(7.1) explicitly forbids '+' here
32-
minusSign = true;
33-
++first;
34-
}
28+
bool const minusSign = (*first == UC('-')); // assume first < last, so dereference without checks;
3529
#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
36-
if (*first == UC('+')) {
30+
if ((*first == UC('-')) || (*first == UC('+'))) {
31+
#else
32+
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
33+
if (*first == UC('-')) {
34+
#endif
3735
++first;
3836
}
39-
#endif
4037
if (last - first >= 3) {
4138
if (fastfloat_strncasecmp(first, str_const_nan<UC>(), 3)) {
4239
answer.ptr = (first += 3);

0 commit comments

Comments
 (0)