From 0ddb0558dcc3f585f9d932b2dc122d3634608dac Mon Sep 17 00:00:00 2001 From: Sandor Dargo Date: Tue, 8 Oct 2024 15:46:39 +0200 Subject: [PATCH] Remove shadowing in decode_integer --- CMakeLists.txt | 2 ++ include/spotify/json/codec/number.hpp | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1db61195..48e78940 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,11 +146,13 @@ target_include_directories(${json_library_TARGET} PUBLIC ${json_INCLUDE_DIR}) if ((CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) target_compile_options(${json_library_TARGET} PRIVATE "-Wunused-parameter") + target_compile_options(${json_library_TARGET} PRIVATE "-Wshadow") endif() if(WIN32) message(STATUS "Building on Windows") target_compile_options(${json_library_TARGET} PRIVATE "/MT$<$:d>") + target_compile_options(${json_library_TARGET} PRIVATE "/w4456") endif() option(SPOTIFY_JSON_USE_SSE42 "Build library with SSE 4.2 support (on x86 and x86-64 platforms)" ON) diff --git a/include/spotify/json/codec/number.hpp b/include/spotify/json/codec/number.hpp index 84e4c5fa..f24ecac4 100644 --- a/include/spotify/json/codec/number.hpp +++ b/include/spotify/json/codec/number.hpp @@ -335,25 +335,25 @@ json_never_inline T decode_integer_tricky(decode_context &context, const char *i template json_never_inline T decode_integer(decode_context &context) { using intops = integer_ops; - const auto b = context.position; - const auto c = next(context); - const auto i = to_integer(c); - fail_if(context, is_invalid_digit(i), "Invalid integer"); - T value = intops::accumulate(0, i); + const auto pos = context.position; + const auto next_char = next(context); + const auto next_char_as_int = to_integer(next_char); + fail_if(context, is_invalid_digit(next_char_as_int), "Invalid integer"); + T value = intops::accumulate(0, next_char_as_int); while (json_likely(context.remaining())) { - const auto c = peek_unchecked(context); - const auto i = to_integer(c); - if (is_invalid_digit(i)) { - const auto is_tricky = ((c == '.') | (c == 'e') | (c == 'E')); - return (json_unlikely(is_tricky) ? decode_integer_tricky(context, b) : value); + const auto next_unchecked = peek_unchecked(context); + const auto next_unchecked_as_int = to_integer(next_unchecked); + if (is_invalid_digit(next_unchecked_as_int)) { + const auto is_tricky = ((next_unchecked == '.') | (next_unchecked == 'e') | (next_unchecked == 'E')); + return (json_unlikely(is_tricky) ? decode_integer_tricky(context, pos) : value); } skip_unchecked_1(context); const auto old_value = value; - value = intops::accumulate(value * 10, i); + value = intops::accumulate(value * 10, next_unchecked_as_int); if (json_unlikely(intops::is_overflow(old_value, value))) { - return decode_integer_tricky(context, b); + return decode_integer_tricky(context, pos); } }