Просмотр исходного кода

Fix `cannot convert 'pgm_p' to 'const void*'` (fixes #1707)

Benoit Blanchon 4 лет назад
Родитель
Сommit
702f8c2e2f

+ 5 - 0
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)
 -------
 

+ 1 - 0
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
 )

+ 17 - 0
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 <ArduinoJson.h>
+
+#include <catch.hpp>
+
+TEST_CASE("Issue1707") {
+  StaticJsonDocument<128> doc;
+
+  DeserializationError err = deserializeJson(doc, F("{\"hello\":12}"));
+  REQUIRE(err == DeserializationError::Ok);
+}

+ 2 - 2
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