Forbid deserializeJson(JsonArray|JsonObject, ...)

Closes #2135
This commit is contained in:
Benoit Blanchon
2024-10-23 15:20:42 +02:00
parent 20219d74f0
commit 0dd6231b3f
5 changed files with 28 additions and 9 deletions

View File

@ -1,6 +1,11 @@
ArduinoJson: change log
=======================
HEAD
----
* Forbid `deserializeJson(JsonArray|JsonObject, ...)` (issue #2135)
v7.2.0 (2024-09-18)
------

View File

@ -34,3 +34,6 @@ build_should_fail(variant_as_char)
add_executable(assign_char assign_char.cpp)
build_should_fail(assign_char)
add_executable(deserialize_object deserialize_object.cpp)
build_should_fail(deserialize_object)

View File

@ -0,0 +1,12 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
// See issue #2135
int main() {
JsonObject obj;
deserializeJson(obj, "");
}

View File

@ -24,14 +24,10 @@ struct first_or_void<T, Rest...> {
// A meta-function that returns true if T is a valid destination type for
// deserialize()
template <class T, class = void>
struct is_deserialize_destination : false_type {};
template <class T>
struct is_deserialize_destination<
T, enable_if_t<is_same<decltype(VariantAttorney::getResourceManager(
detail::declval<T&>())),
ResourceManager*>::value>> : true_type {};
using is_deserialize_destination =
bool_constant<is_base_of<JsonDocument, remove_cv_t<T>>::value ||
IsVariant<T>::value>;
template <typename TDestination>
inline void shrinkJsonDocument(TDestination&) {

View File

@ -13,7 +13,10 @@ struct integral_constant {
static const T value = v;
};
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
template <bool B>
using bool_constant = integral_constant<bool, B>;
using true_type = bool_constant<true>;
using false_type = bool_constant<false>;
ARDUINOJSON_END_PRIVATE_NAMESPACE