Files
json/single_include
Niels Lohmann b0a4218e38 Report the same error position for bulk number runs as for byte-wise input
For contiguous input, the CBOR and MessagePack readers read the
scalars of an array in one loop, and the UBJSON/BJData readers the
numbers of an optimized array. These loops passed a value on before
they advanced the position and the last byte. With a number_float_t
narrower than the value (for example float), passing the value on
reports out_of_range.406, and SAX parse_error() then got a different
position and last token than for the same bytes read through a
non-contiguous adapter.

Advance before passing the value on in the CBOR and MessagePack loops.
The last byte is the head byte, as get_number() does not change it;
the MessagePack loop used the last byte of the value. In the typed
UBJSON/BJData loop, update the position per value only where passing
it on can report an error, which is decided at compile time and never
the case for the default number types, and do not change the last byte,
as reading the values one by one does not.

Instruction counts of SAX and DOM parsing of arrays of one million
numbers: CBOR -1 to -4 %, MessagePack -2 to -10 %, UBJSON/BJData typed
arrays -0.8 to +0.6 % (clang, -O2).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-16 07:41:29 +01:00
..