From 7a6e28acfaeb52ba322116e188cb2b7ce1603dc2 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Fri, 3 Jun 2022 21:05:44 +0200 Subject: [PATCH] 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. --- include/nlohmann/json.hpp | 1 + single_include/nlohmann/json.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 7a1030c76..629a3edef 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -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(); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 91b31eda4..c342172b4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -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(); } -- GitLab