Skip to content

Commit

Permalink
Merge pull request #236 from fastfloat/issue235
Browse files Browse the repository at this point in the history
Verify and fix issue 235
  • Loading branch information
lemire authored Jan 28, 2024
2 parents f320619 + 7977ec6 commit a642af5
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 138 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ubuntu22-sanitize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Ubuntu 22.04 CI Sanitized (GCC 11)

on: [push, pull_request]

jobs:
ubuntu-build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Use cmake
run: |
mkdir build &&
cd build &&
cmake -DFASTFLOAT_TEST=ON -D FASTFLOAT_SANITIZE=ON .. &&
cmake --build . &&
ctest --output-on-failure
6 changes: 5 additions & 1 deletion fuzz/from_chars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
auto answer =
fast_float::from_chars(input_d.data(), input_d.data() + input_d.size(), result_d, format);
std::string input_f = fdp.ConsumeRandomLengthString(128);
double result_f = 0.0;
float result_f = 0.0;
answer =
fast_float::from_chars(input_f.data(), input_f.data() + input_f.size(), result_f, format);
int result_i = 0;
std::string input_i = fdp.ConsumeRandomLengthString(128);
answer =
fast_float::from_chars(input_i.data(), input_i.data() + input_i.size(), result_i);
return 0;
}
7 changes: 4 additions & 3 deletions include/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ parsed_number_string_t<UC> parse_number_string(UC const *p, UC const * pend, par

template <typename T, typename UC>
fastfloat_really_inline FASTFLOAT_CONSTEXPR20
from_chars_result_t<UC> parse_int_string(UC const* p, UC const* pend, T& value, int base)
{
from_chars_result_t<UC> parse_int_string(UC const* p, UC const* pend, T& value, int base) {
from_chars_result_t<UC> answer;

UC const* const first = p;
Expand All @@ -463,9 +462,11 @@ from_chars_result_t<UC> parse_int_string(UC const* p, UC const* pend, T& value,
}

UC const* const start_num = p;
while (*p == UC('0')) {

while (p!= pend && *p == UC('0')) {
++p;
}

const bool has_leading_zeros = p > start_num;

UC const* const start_digits = p;
Expand Down
3 changes: 1 addition & 2 deletions include/fast_float/parse_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,

template <typename T, typename UC, typename>
FASTFLOAT_CONSTEXPR20
from_chars_result_t<UC> from_chars(UC const* first, UC const* last, T& value, int base) noexcept
{
from_chars_result_t<UC> from_chars(UC const* first, UC const* last, T& value, int base) noexcept {
static_assert (is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported");

from_chars_result_t<UC> answer;
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option(FASTFLOAT_SUPPLEMENTAL_TESTS "Run supplemental tests" ON)
if (NOT SYSTEM_DOCTEST)
FetchContent_Declare(doctest
GIT_REPOSITORY https://github.com/onqtam/doctest.git
GIT_TAG v2.4.10)
GIT_TAG v2.4.11)
endif()
if (FASTFLOAT_SUPPLEMENTAL_TESTS)
FetchContent_Declare(supplemental_test_files
Expand Down Expand Up @@ -81,6 +81,7 @@ fast_float_add_cpp_test(long_test)
fast_float_add_cpp_test(powersoffive_hardround)
fast_float_add_cpp_test(string_test)
fast_float_add_cpp_test(fast_int)
target_compile_features(fast_int PRIVATE cxx_std_17)
fast_float_add_cpp_test(json_fmt)
fast_float_add_cpp_test(fortran)

Expand Down
Loading

0 comments on commit a642af5

Please sign in to comment.