The /cmd getters serialized into fixed stack buffers (get_stats 20480,
get_meta 2048, get_protocols 102400). When a report exceeded its buffer
the output was silently corrupted into invalid JSON, not cleanly
truncated: the abuf string builder drops an oversized chunk but keeps
appending the smaller chunks that follow, so e.g. a get_stats reply with
~230 enabled decoders ended like `...,"name":,:8256}`. Clients then fail
to parse the response and the corresponding data never updates.
Make the serializer report truncation and add data_print_jsons_dup(),
which grows a heap buffer until the whole document fits, and use it for
the three JSON-payload getters:
- abuf gains an `overflow` flag, set by abuf_cat/abuf_printf and the
hand-rolled string formatter whenever a write is dropped or truncated.
- data_print_jsons_dup() retries with a doubled buffer until no overflow
(64 MiB sanity cap), so the report is never truncated.
- get_stats/get_meta/get_protocols use it and free the buffer after
responding; out-of-memory yields an error reply instead of a partial one.
Tests:
- data-test asserts a large report serializes to a complete object via
data_print_jsons_dup() while a fixed undersized buffer does not.
- the HTTP integration test now validates that get_protocols/get_stats/
get_meta return parseable JSON, not just HTTP 200.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Change hard coded strings are "const" so any variable pointing to them must also have the const specifier to avoid a warning (from -Wdiscarded-qualifiers)
- Change local variables manipulating constant strings must also have the const qualifier
- Change hostport_param, fix remaining hostport_param args
Co-authored-by: Christian W. Zuckschwerdt <christian@zuckschwerdt.org>
The rationale behind these patches are pretty much in the source comments. MSVC issues with:
*) "Variable Length Arrays"
*) 'restrict` keyword.
*) And '<strings.h>'.
Adds a new interface for constructing, printing and releasing data_t*
structures. The data structure describes typed hierarchical data (much like
json) and then provides a function for dumping it to a file descriptor.
It comes with a small test.