mirror of
https://github.com/nlohmann/json.git
synced 2026-09-01 14:07:14 +00:00
Fix GCC narrowing warning and address review feedback
- get_bytes(): replace `len -= static_cast<NumberType>(wanted)` with an explicit `len = static_cast<NumberType>(len - ...)`. The compound assignment promoted the operands to int and narrowed back, which GCC rejects under -Werror=arith-conversion when NumberType is narrower than int (e.g. UBJSON's int16 length). This also fixes the CodeQL build. - get_bytes(): add JSON_ASSERT(read == wanted) documenting that get_elements() never returns more than requested (per review). - iterator_input_adapter: de-duplicate the iterator_is_contiguous definition with the #if inside the initializer (per review). - Add a comment explaining why the memcpy source is &*current (needed for non-pointer contiguous iterators), and drop the redundant parentheses. - Run astyle on the new unit test so the amalgamation/format check passes. Signed-off-by: Niels Lohmann <mail@nlohmann.me> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9eee7a7b9b
commit
282ff6ce5c
@@ -2785,10 +2785,10 @@ TEST_CASE("CBOR large strings and binaries (chunked reader)")
|
||||
// sure roundtripping is correct for lengths around and beyond the internal
|
||||
// chunk size (4096 bytes), for both vector (iterator) and pointer inputs.
|
||||
for (const std::size_t len :
|
||||
{
|
||||
std::size_t{0}, std::size_t{1}, std::size_t{4095}, std::size_t{4096},
|
||||
std::size_t{4097}, std::size_t{8192}, std::size_t{100000}
|
||||
})
|
||||
{
|
||||
std::size_t{0}, std::size_t{1}, std::size_t{4095}, std::size_t{4096},
|
||||
std::size_t{4097}, std::size_t{8192}, std::size_t{100000}
|
||||
})
|
||||
{
|
||||
CAPTURE(len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user