From 702f8c2e2f6b317dbc4894e2b480ddf44c5cf207 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 6 Feb 2022 11:14:23 +0100 Subject: [PATCH] Fix `cannot convert 'pgm_p' to 'const void*'` (fixes #1707) --- CHANGELOG.md | 5 +++++ extras/tests/MixedConfiguration/CMakeLists.txt | 1 + extras/tests/MixedConfiguration/issue1707.cpp | 17 +++++++++++++++++ src/ArduinoJson/Polyfills/pgmspace.hpp | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 extras/tests/MixedConfiguration/issue1707.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 47dff0bf..337ca255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fix `cannot convert 'pgm_p' to 'const void*'` (issue #1707) + v6.19.1 (2022-01-14) ------- diff --git a/extras/tests/MixedConfiguration/CMakeLists.txt b/extras/tests/MixedConfiguration/CMakeLists.txt index a0b10b7c..01d1216e 100644 --- a/extras/tests/MixedConfiguration/CMakeLists.txt +++ b/extras/tests/MixedConfiguration/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(MixedConfigurationTests enable_progmem_1.cpp enable_string_deduplication_0.cpp enable_string_deduplication_1.cpp + issue1707.cpp use_double_0.cpp use_double_1.cpp ) diff --git a/extras/tests/MixedConfiguration/issue1707.cpp b/extras/tests/MixedConfiguration/issue1707.cpp new file mode 100644 index 00000000..befdee53 --- /dev/null +++ b/extras/tests/MixedConfiguration/issue1707.cpp @@ -0,0 +1,17 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2022, Benoit BLANCHON +// MIT License + +#define ARDUINO +#define memcpy_P(dest, src, n) memcpy((dest), (src), (n)) + +#include + +#include + +TEST_CASE("Issue1707") { + StaticJsonDocument<128> doc; + + DeserializationError err = deserializeJson(doc, F("{\"hello\":12}")); + REQUIRE(err == DeserializationError::Ok); +} diff --git a/src/ArduinoJson/Polyfills/pgmspace.hpp b/src/ArduinoJson/Polyfills/pgmspace.hpp index 18925170..afef4ce9 100644 --- a/src/ArduinoJson/Polyfills/pgmspace.hpp +++ b/src/ArduinoJson/Polyfills/pgmspace.hpp @@ -99,7 +99,7 @@ inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) { #ifndef pgm_read_dword inline uint32_t pgm_read_dword(ARDUINOJSON_NAMESPACE::pgm_p p) { uint32_t result; - memcpy_P(&result, p, 4); + memcpy_P(&result, p.address, 4); return result; } #endif @@ -107,7 +107,7 @@ inline uint32_t pgm_read_dword(ARDUINOJSON_NAMESPACE::pgm_p p) { #ifndef pgm_read_ptr inline void* pgm_read_ptr(ARDUINOJSON_NAMESPACE::pgm_p p) { void* result; - memcpy_P(&result, p, sizeof(result)); + memcpy_P(&result, p.address, sizeof(result)); return result; } #endif