Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove shadowing in decode_integer #69

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>: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)
Expand Down
24 changes: 12 additions & 12 deletions include/spotify/json/codec/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,25 @@ json_never_inline T decode_integer_tricky(decode_context &context, const char *i
template <typename T, bool is_positive>
json_never_inline T decode_integer(decode_context &context) {
using intops = integer_ops<T, is_positive>;
const auto b = context.position;
const auto c = next(context);
const auto i = to_integer<T>(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<T>(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<T>(c);
if (is_invalid_digit(i)) {
const auto is_tricky = ((c == '.') | (c == 'e') | (c == 'E'));
return (json_unlikely(is_tricky) ? decode_integer_tricky<T, is_positive>(context, b) : value);
const auto next_unchecked = peek_unchecked(context);
const auto next_unchecked_as_int = to_integer<T>(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<T, is_positive>(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<T, is_positive>(context, b);
return decode_integer_tricky<T, is_positive>(context, pos);
}
}

Expand Down