diff --git a/CHANGELOG.md b/CHANGELOG.md index f20e1a4e..f5aaf8dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ArduinoJson: change log HEAD ---- +* Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978) * Fixed invalid result from `operator|` (issue #981) > ### BREAKING CHANGE diff --git a/appveyor.yml b/appveyor.yml index 031fdb18..fa48679c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,4 +17,4 @@ before_build: build_script: - cmake --build . --config %CONFIGURATION% test_script: -- ctest --output-on-failure . +- ctest -C %CONFIGURATION% --output-on-failure . diff --git a/src/ArduinoJson/Deserialization/CharPointerReader.hpp b/src/ArduinoJson/Deserialization/CharPointerReader.hpp index 6a35153c..b48cd921 100644 --- a/src/ArduinoJson/Deserialization/CharPointerReader.hpp +++ b/src/ArduinoJson/Deserialization/CharPointerReader.hpp @@ -6,6 +6,16 @@ namespace ARDUINOJSON_NAMESPACE { +template +struct IsCharOrVoid { + static const bool value = + is_same::value || is_same::value || + is_same::value || is_same::value; +}; + +template +struct IsCharOrVoid : IsCharOrVoid {}; + class UnsafeCharPointerReader { const char* _ptr; @@ -41,12 +51,16 @@ class SafeCharPointerReader { }; template -inline UnsafeCharPointerReader makeReader(TChar* input) { +inline typename enable_if::value, + UnsafeCharPointerReader>::type +makeReader(TChar* input) { return UnsafeCharPointerReader(reinterpret_cast(input)); } template -inline SafeCharPointerReader makeReader(TChar* input, size_t n) { +inline + typename enable_if::value, SafeCharPointerReader>::type + makeReader(TChar* input, size_t n) { return SafeCharPointerReader(reinterpret_cast(input), n); } diff --git a/test/Misc/CMakeLists.txt b/test/Misc/CMakeLists.txt index 9e8817ab..724c192d 100644 --- a/test/Misc/CMakeLists.txt +++ b/test/Misc/CMakeLists.txt @@ -13,3 +13,24 @@ add_executable(MiscTests target_link_libraries(MiscTests catch) add_test(Misc MiscTests) + + +add_executable(Issue978 + Issue978.cpp +) +set_target_properties(Issue978 + PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE +) +add_test( + NAME + Issue978 + COMMAND + ${CMAKE_COMMAND} --build . --target Issue978 --config $ + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR} +) +set_tests_properties(Issue978 + PROPERTIES + WILL_FAIL TRUE) diff --git a/test/Misc/Issue978.cpp b/test/Misc/Issue978.cpp new file mode 100644 index 00000000..927f99c0 --- /dev/null +++ b/test/Misc/Issue978.cpp @@ -0,0 +1,13 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2019 +// MIT License + +#include + +struct Stream {}; + +int main() { + Stream* stream = 0; + DynamicJsonDocument doc(1024); + deserializeJson(doc, stream); +}