bblanchon / ArduinoJson

📟 JSON library for Arduino and embedded C++. Simple and efficient.
https://arduinojson.org
MIT License
6.67k stars 1.11k forks source link

ArduinoJson 7.1.0 Compile error [ invalid use of array with unspecified bounds ] #2112

Closed gmgunderground closed 1 month ago

gmgunderground commented 1 month ago

Description invalid use of array with unspecified bounds

.pio\libdeps\uno_r4minima\ArduinoJson\src/ArduinoJson/Serialization/Writer.hpp:22:19: error: invalid use of array with unspecified bounds return dest->write(s, n);

Troubleshooter's report

  1. The program uses ArduinoJson 7
  2. The issue happens at compile time
  3. The error is not in the list

Environment

Reproduction code

#include <ArduinoJson.h>

uint8_t vsp_tx_buffer[VSP_TX_BUFFER_SIZE];

void setup()
{
        JsonDocument doc;

        doc["CMD"] = 0x123;
        doc["Extra"] = 9;

         uint16_t n = serializeJsonPretty(doc, vsp_tx_buffer);
}
gmgunderground commented 1 month ago

I found the problem, as reported in documentation serializeJsonPretty acept char and i'm using "unsigned char" because I'm using a memory buffer size_t serializeJsonPretty(const JsonDocument& doc, char output[size]); from the mempry perspetive char and unsigned char are the same element, baut if I use (and is not rare to use a unsigned char buffers in embedded) I can't serialize my object if I don't create a slow my custom writer

bblanchon commented 1 month ago

Hi @gmgunderground,

I don't get any error with the provided sample code. See this online demo: https://wandbox.org/permlink/Tu38w0wCx8SNfy7F

Please provide a sample code that reproduces the error.

Best regards, Benoit