From eb8f2bce1430bb42d222085635667b261960fc1a Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 11 Jun 2024 13:55:55 -0400 Subject: [PATCH] fix: add test for issue 2199 (#2200) * fix: add test for issue 2199 * added ubuntu 24 workflow + silencing a warning --- .github/workflows/ubuntu24.yml | 24 +++++++++++++++++++++ tests/ondemand/ondemand_misc_tests.cpp | 30 ++++++++++++++++++++------ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ubuntu24.yml diff --git a/.github/workflows/ubuntu24.yml b/.github/workflows/ubuntu24.yml new file mode 100644 index 000000000..742f680ce --- /dev/null +++ b/.github/workflows/ubuntu24.yml @@ -0,0 +1,24 @@ +name: Ubuntu 24.04 CI + +on: [push, pull_request] +jobs: + ubuntu-build: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + runs-on: ubuntu-24.04 + strategy: + matrix: + shared: [ON, OFF] + cxx: [g++-13, clang++-16] + sanitizer: [ON, OFF] + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + - name: Prepare + run: cmake -DSIMDJSON_DEVELOPER_MODE=ON -DSIMDJSON_SANITIZE=${{matrix.sanitizer}} -DBUILD_SHARED_LIBS=${{matrix.shared}} -B build + env: + CXX: ${{matrix.cxx}} + - name: Build + run: cmake --build build -j=2 + - name: Test + run: ctest --output-on-failure --test-dir build \ No newline at end of file diff --git a/tests/ondemand/ondemand_misc_tests.cpp b/tests/ondemand/ondemand_misc_tests.cpp index 826ee5477..c24563717 100644 --- a/tests/ondemand/ondemand_misc_tests.cpp +++ b/tests/ondemand/ondemand_misc_tests.cpp @@ -5,6 +5,22 @@ using namespace simdjson; namespace misc_tests { using namespace std; +#if SIMDJSON_EXCEPTIONS + // user reported an asan error: + bool issue2199() { + TEST_START(); + static constexpr std::string_view kJsonString = R"( { "name": "name", "version": 100, } )"; + try { + simdjson::padded_string buffer{kJsonString}; + simdjson::ondemand::parser parser; + simdjson::ondemand::document document = parser.iterate(buffer); + (void)document; + } catch (simdjson::simdjson_error& /*error*/) { + std::cerr << "Caught simdjson_error" << std::endl; + } + TEST_SUCCEED(); + } +#endif bool issue1981_success() { auto error_phrase = R"(false)"_padded; TEST_START(); @@ -532,7 +548,7 @@ namespace misc_tests { string_view token; ASSERT_SUCCESS(o["value"].raw_json_token().get(token)); ASSERT_EQUAL(token, "12321323213213213213213213213211223"); - return true; + TEST_SUCCEED(); } simdjson_warn_unused bool big_integer_in_string() { TEST_START(); @@ -545,7 +561,7 @@ namespace misc_tests { string_view token; ASSERT_SUCCESS(o["value"].raw_json_token().get(token)); ASSERT_EQUAL(token, "\"12321323213213213213213213213211223\""); - return true; + TEST_SUCCEED(); } simdjson_warn_unused bool test_raw_json_token(string_view json, string_view expected_token, int expected_start_index = 0) { string title("'"); @@ -558,7 +574,7 @@ namespace misc_tests { ASSERT_EQUAL( token, expected_token ); // Validate the text is inside the original buffer ASSERT_EQUAL( reinterpret_cast(token.data()), reinterpret_cast(&json_padded.data()[expected_start_index])); - return true; + TEST_SUCCEED(); })); // Test values @@ -576,10 +592,9 @@ namespace misc_tests { // Validate the text is inside the original buffer // Adjust for the {"a": ASSERT_EQUAL( reinterpret_cast(token.data()), reinterpret_cast(&json_padded.data()[5+expected_start_index])); - return true; + TEST_SUCCEED(); })); - - return true; + TEST_SUCCEED(); } bool raw_json_token() { @@ -605,6 +620,9 @@ namespace misc_tests { bool run() { return +#if SIMDJSON_EXCEPTIONS + issue2199() && +#endif skipbom() && issue1981_success() && issue1981_failure() &&