mirror of
https://github.com/esphome/esphome.git
synced 2026-03-01 10:24:19 -07:00
[json] Make heap fallback max size constexpr
This commit is contained in:
@@ -123,8 +123,9 @@ SerializationBuffer<> JsonBuilder::serialize() {
|
||||
// In practice, one iteration (1024 bytes) covers all known entity types.
|
||||
// Payloads exceeding 1024 bytes are not known to exist in real configurations.
|
||||
// Cap at 4096 as a safety limit to prevent runaway allocation.
|
||||
constexpr size_t max_heap_size = 4096;
|
||||
size_t heap_size = buf_size * 2;
|
||||
while (heap_size <= 4096) {
|
||||
while (heap_size <= max_heap_size) {
|
||||
result.reallocate_heap_(heap_size - 1);
|
||||
size = serializeJson(doc_, result.data_writable_(), heap_size);
|
||||
if (size < heap_size) {
|
||||
|
||||
Reference in New Issue
Block a user