diff --git a/include/nlohmann/detail/input/string_scan.hpp b/include/nlohmann/detail/input/string_scan.hpp index 40fea65ef..91a837e39 100644 --- a/include/nlohmann/detail/input/string_scan.hpp +++ b/include/nlohmann/detail/input/string_scan.hpp @@ -242,7 +242,7 @@ unit-class_lexer.cpp checks every entry of the table. */ inline const std::uint64_t* utf8_dfa_table() noexcept { - static const std::array table = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static const std::array table = { { 0x0000000000000180ull, 0x0000000000000180ull, 0x0000000000000180ull, 0x0000000000000180ull, @@ -401,8 +401,9 @@ inline std::size_t valid_utf8_prefix(const unsigned char* data, std::size_t n) n continue; } - pos = static_cast(utf8_dfa_prefix(data + pos, data + n) - data); - if (pos != n && data[pos] >= 0x80u) + const unsigned char* const last = utf8_dfa_prefix(data + pos, data + n); + pos = static_cast(last - data); + if (pos != n && *last >= 0x80u) { break; // ill-formed or truncated } @@ -702,7 +703,7 @@ JSON_HEDLEY_ALWAYS_INLINE std::size_t lexer_string_bulk_run(const unsigned char* // unaffected by this fast path. inline int hex_codepoint(const unsigned char* data) noexcept { - static const std::array hex_digit_table = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static const std::array hex_digit_table = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 00..0F diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index e967c37f7..470088450 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13191,7 +13191,7 @@ unit-class_lexer.cpp checks every entry of the table. */ inline const std::uint64_t* utf8_dfa_table() noexcept { - static const std::array table = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static const std::array table = { { 0x0000000000000180ull, 0x0000000000000180ull, 0x0000000000000180ull, 0x0000000000000180ull, @@ -13350,8 +13350,9 @@ inline std::size_t valid_utf8_prefix(const unsigned char* data, std::size_t n) n continue; } - pos = static_cast(utf8_dfa_prefix(data + pos, data + n) - data); - if (pos != n && data[pos] >= 0x80u) + const unsigned char* const last = utf8_dfa_prefix(data + pos, data + n); + pos = static_cast(last - data); + if (pos != n && *last >= 0x80u) { break; // ill-formed or truncated } @@ -13651,7 +13652,7 @@ JSON_HEDLEY_ALWAYS_INLINE std::size_t lexer_string_bulk_run(const unsigned char* // unaffected by this fast path. inline int hex_codepoint(const unsigned char* data) noexcept { - static const std::array hex_digit_table = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + static const std::array hex_digit_table = { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 00..0F