From 68d1596427285db9eecfe46e2c412890b67b92af Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 28 Aug 2026 14:50:29 +0000 Subject: [PATCH] Do not repeat the integer conversion that just failed scan_number_bulk_contiguous() converts an integer token straight from the input buffer. When the value does not fit, it materializes token_buffer and calls convert_number(), which tried the very same integer conversion again before falling back to floating point. Recording the outcome in number_type skips the second attempt. The resulting token type and value are unchanged: convert_number() reached the float tail either way. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01MXDi7NTMKAmoArUZSKMc4T Signed-off-by: Niels Lohmann --- include/nlohmann/detail/input/lexer.hpp | 5 ++++- single_include/nlohmann/json.hpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 62d517e86..4c3665593 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1538,7 +1538,10 @@ scan_number_done: position.chars_read_current_line += (len - 1); return integer_result; } - // the value overflowed: fall through and let the float tail handle it + // The value does not fit an integer, so this token converts as a + // float. Recording that here keeps convert_number() below from + // repeating the integer attempt that just failed. + number_type = token_type::value_float; } #endif diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 9ba0445a3..955add0ef 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -9885,7 +9885,10 @@ scan_number_done: position.chars_read_current_line += (len - 1); return integer_result; } - // the value overflowed: fall through and let the float tail handle it + // The value does not fit an integer, so this token converts as a + // float. Recording that here keeps convert_number() below from + // repeating the integer attempt that just failed. + number_type = token_type::value_float; } #endif