From 5355190cff11485374972ab8303b7b5991e452a6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 4 Jul 2026 09:01:54 +0200 Subject: [PATCH] Rename get_bytes' local `read` to `bytes_read` Flawfinder flags the bare identifier `read` as the POSIX read() syscall (CWE-120/CWE-20), producing several false-positive code-scanning alerts. Renaming the local variable removes them; the byte-copy itself is unchanged and remains bounds-checked (get_elements caps the copy to the bytes available). This is a pure rename with identical semantics. Signed-off-by: Niels Lohmann Co-Authored-By: Claude Opus 4.8 --- include/nlohmann/detail/input/binary_reader.hpp | 10 +++++----- single_include/nlohmann/json.hpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 9d07ecebb..5093e032b 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -2970,20 +2970,20 @@ class binary_reader : chunk_size; const std::size_t old_size = result.size(); result.resize(old_size + wanted); - const std::size_t read = ia.get_elements(&result[old_size], wanted); - chars_read += read; - if (JSON_HEDLEY_UNLIKELY(read < wanted)) + const std::size_t bytes_read = ia.get_elements(&result[old_size], wanted); + chars_read += bytes_read; + if (JSON_HEDLEY_UNLIKELY(bytes_read < wanted)) { // premature end of input: shrink to what was actually read and // report the failure at the first missing byte (same position // accounting as get_to() for partial number reads) - result.resize(old_size + read); + result.resize(old_size + bytes_read); ++chars_read; current = char_traits::eof(); return unexpect_eof(format, context); } // a full chunk was read; get_elements() never returns more than requested - JSON_ASSERT(read == wanted); + JSON_ASSERT(bytes_read == wanted); len = static_cast(len - static_cast(wanted)); } return true; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 6a7b82224..6f18a1bf5 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13171,20 +13171,20 @@ class binary_reader : chunk_size; const std::size_t old_size = result.size(); result.resize(old_size + wanted); - const std::size_t read = ia.get_elements(&result[old_size], wanted); - chars_read += read; - if (JSON_HEDLEY_UNLIKELY(read < wanted)) + const std::size_t bytes_read = ia.get_elements(&result[old_size], wanted); + chars_read += bytes_read; + if (JSON_HEDLEY_UNLIKELY(bytes_read < wanted)) { // premature end of input: shrink to what was actually read and // report the failure at the first missing byte (same position // accounting as get_to() for partial number reads) - result.resize(old_size + read); + result.resize(old_size + bytes_read); ++chars_read; current = char_traits::eof(); return unexpect_eof(format, context); } // a full chunk was read; get_elements() never returns more than requested - JSON_ASSERT(read == wanted); + JSON_ASSERT(bytes_read == wanted); len = static_cast(len - static_cast(wanted)); } return true;