Skip to content

Commit

Permalink
Fix assertion failure with floats with multiple signs
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Jan 21, 2024
1 parent 6c4186d commit 7e014d4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fuzz-batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
sanitizer:
- address
- undefined
- memory
#- memory

steps:
- name: Build fuzzers
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fuzz-continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
sanitizer:
- address
- undefined
- memory
#- memory

steps:
- name: Build fuzzers
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fuzz-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
sanitizer:
- address
- undefined
- memory
#- memory

steps:
- name: Build fuzzers
Expand Down
12 changes: 12 additions & 0 deletions src/scn/impl/reader/float_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,18 @@ scan_expected<std::ptrdiff_t> dispatch_impl(
return static_cast<std::ptrdiff_t>(5 + nan_payload.view().size());
}

SCN_EXPECT(!data.input.view().empty());
if (data.kind == float_reader_base::float_kind::hex_without_prefix) {
if (SCN_UNLIKELY(char_to_int(data.input.view().front()) >= 16)) {
return unexpected_scan_error(scan_error::invalid_scanned_value,
"Invalid floating-point digit");
}
}
if (SCN_UNLIKELY(char_to_int(data.input.view().front()) >= 10)) {
return unexpected_scan_error(scan_error::invalid_scanned_value,
"Invalid floating-point digit");
}

if constexpr (std::is_same_v<T, long double>) {
if constexpr (sizeof(double) == sizeof(long double)) {
// If double == long double (true on Windows),
Expand Down
5 changes: 5 additions & 0 deletions tests/unittests/float_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ TEST(FloatTest, FloatWithSuffix)
EXPECT_DOUBLE_EQ(result->value(), 0.0075);
EXPECT_TRUE(result->range().empty());
}

TEST(FloatTest, FloatWithDoubleSign) {
auto result = scn::scan<double>("--4", "{}");
ASSERT_FALSE(result);
}

0 comments on commit 7e014d4

Please sign in to comment.