Skip to content

Commit 7a6e28a

Browse files
Add assertion to converting constructor (#3517)
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.
1 parent 560cede commit 7a6e28a

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

include/nlohmann/json.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
916916
default: // LCOV_EXCL_LINE
917917
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
918918
}
919+
JSON_ASSERT(m_type == val.type());
919920
set_parents();
920921
assert_invariant();
921922
}

single_include/nlohmann/json.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19190,6 +19190,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
1919019190
default: // LCOV_EXCL_LINE
1919119191
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
1919219192
}
19193+
JSON_ASSERT(m_type == val.type());
1919319194
set_parents();
1919419195
assert_invariant();
1919519196
}

0 commit comments

Comments
 (0)