diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 7ebec2493..5776afb67 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1490,9 +1490,11 @@ scan_number_done: const std::size_t len = i; // materialize the token exactly as scan_number() would, substituting the - // locale decimal point so convert_number()'s strtof fallback stays valid + // locale decimal point so convert_number()'s strtof fallback stays valid. + // reset() already cleared token_buffer, so append() fills it (assign() is + // avoided because custom string_t types need not provide it) reset(); - token_buffer.assign(data, len); + token_buffer.append(reinterpret_cast(data), len); if (dot_index != std::string::npos) { token_buffer[dot_index] = static_cast(decimal_point_char); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 33442ab76..be3da54ca 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -9738,9 +9738,11 @@ scan_number_done: const std::size_t len = i; // materialize the token exactly as scan_number() would, substituting the - // locale decimal point so convert_number()'s strtof fallback stays valid + // locale decimal point so convert_number()'s strtof fallback stays valid. + // reset() already cleared token_buffer, so append() fills it (assign() is + // avoided because custom string_t types need not provide it) reset(); - token_buffer.assign(data, len); + token_buffer.append(reinterpret_cast(data), len); if (dot_index != std::string::npos) { token_buffer[dot_index] = static_cast(decimal_point_char);