From c1a507c158810f28a8bd34dc0c16fa1b3636add1 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Wed, 11 Sep 2024 21:08:51 +0200 Subject: [PATCH] Set `ARDUINOJSON_POOL_CAPACITY` from `ARDUINOJSON_SLOT_ID_SIZE` This avoids the integer overflow when `ARDUINOJSON_SLOT_ID_SIZE=1` on 64-bit architectures. --- extras/conf_test/avr.cpp | 2 ++ extras/conf_test/esp8266.cpp | 2 ++ extras/conf_test/x64.cpp | 2 ++ extras/conf_test/x86.cpp | 2 ++ src/ArduinoJson/Configuration.hpp | 4 ++-- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extras/conf_test/avr.cpp b/extras/conf_test/avr.cpp index eeac6c0d..769317a8 100644 --- a/extras/conf_test/avr.cpp +++ b/extras/conf_test/avr.cpp @@ -6,6 +6,8 @@ static_assert(ARDUINOJSON_USE_LONG_LONG == 0, "ARDUINOJSON_USE_LONG_LONG"); static_assert(ARDUINOJSON_SLOT_ID_SIZE == 1, "ARDUINOJSON_SLOT_ID_SIZE"); +static_assert(ARDUINOJSON_POOL_CAPACITY == 16, "ARDUINOJSON_POOL_CAPACITY"); + static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 0, "ARDUINOJSON_USE_DOUBLE"); diff --git a/extras/conf_test/esp8266.cpp b/extras/conf_test/esp8266.cpp index 18d0d753..b37bfd67 100644 --- a/extras/conf_test/esp8266.cpp +++ b/extras/conf_test/esp8266.cpp @@ -4,6 +4,8 @@ static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG"); static_assert(ARDUINOJSON_SLOT_ID_SIZE == 2, "ARDUINOJSON_SLOT_ID_SIZE"); +static_assert(ARDUINOJSON_POOL_CAPACITY == 128, "ARDUINOJSON_POOL_CAPACITY"); + static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); diff --git a/extras/conf_test/x64.cpp b/extras/conf_test/x64.cpp index c7ce9ae2..df6b044b 100644 --- a/extras/conf_test/x64.cpp +++ b/extras/conf_test/x64.cpp @@ -4,6 +4,8 @@ static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG"); static_assert(ARDUINOJSON_SLOT_ID_SIZE == 4, "ARDUINOJSON_SLOT_ID_SIZE"); +static_assert(ARDUINOJSON_POOL_CAPACITY == 256, "ARDUINOJSON_POOL_CAPACITY"); + static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); diff --git a/extras/conf_test/x86.cpp b/extras/conf_test/x86.cpp index a5f335e8..9dff8f17 100644 --- a/extras/conf_test/x86.cpp +++ b/extras/conf_test/x86.cpp @@ -4,6 +4,8 @@ static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG"); static_assert(ARDUINOJSON_SLOT_ID_SIZE == 2, "ARDUINOJSON_SLOT_ID_SIZE"); +static_assert(ARDUINOJSON_POOL_CAPACITY == 128, "ARDUINOJSON_POOL_CAPACITY"); + static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); diff --git a/src/ArduinoJson/Configuration.hpp b/src/ArduinoJson/Configuration.hpp index 21006bc3..cf6fb383 100644 --- a/src/ArduinoJson/Configuration.hpp +++ b/src/ArduinoJson/Configuration.hpp @@ -110,9 +110,9 @@ // Capacity of each variant pool (in slots) #ifndef ARDUINOJSON_POOL_CAPACITY -# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# if ARDUINOJSON_SLOT_ID_SIZE == 1 # define ARDUINOJSON_POOL_CAPACITY 16 // 96 bytes -# elif ARDUINOJSON_SIZEOF_POINTER == 4 +# elif ARDUINOJSON_SLOT_ID_SIZE == 2 # define ARDUINOJSON_POOL_CAPACITY 128 // 1024 bytes # else # define ARDUINOJSON_POOL_CAPACITY 256 // 4096 bytes