Skip to content

Commit

Permalink
Add assertion to converting constructor (nlohmann#3517)
Browse files Browse the repository at this point in the history
The converting basic_json constructor can inadvertently change the value
type of its parameter. Assert that both basic_json values are of the
same value type after conversion.
  • Loading branch information
falbrechtskirchinger authored Jun 3, 2022
1 parent 560cede commit 7a6e28a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
}
JSON_ASSERT(m_type == val.type());
set_parents();
assert_invariant();
}
Expand Down
1 change: 1 addition & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19190,6 +19190,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
default: // LCOV_EXCL_LINE
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
}
JSON_ASSERT(m_type == val.type());
set_parents();
assert_invariant();
}
Expand Down

0 comments on commit 7a6e28a

Please sign in to comment.