From df1dda712ec28fcdf6ac5263d92e4b27d33e8ab1 Mon Sep 17 00:00:00 2001 From: Colby Haskell Date: Sun, 5 Nov 2023 10:20:14 -0500 Subject: [PATCH] Fix swapped signed and unsigned char types --- include/nlohmann/detail/input/input_adapters.hpp | 12 ++++++++++-- single_include/nlohmann/json.hpp | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 35a9a64fa..0f8d5c3c9 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -25,6 +25,7 @@ #include #include +#include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail @@ -141,14 +142,21 @@ struct char_traits : std::char_traits template<> struct char_traits : std::char_traits { - using char_type = signed char; + using char_type = unsigned char; + using int_type = unsigned long; + + // Redefine to_int_type function + static int_type to_int_type(char_type c) + { + return static_cast(c); + } }; // Explicitly define char traits for signed char since it is not standard template<> struct char_traits : std::char_traits { - using char_type = unsigned char; + using char_type = signed char; }; // General-purpose iterator-based adapter. It might not be as fast as diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 78d652091..3b2765656 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -6107,6 +6107,8 @@ NLOHMANN_JSON_NAMESPACE_END // #include +// #include + NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail @@ -6223,14 +6225,21 @@ struct char_traits : std::char_traits template<> struct char_traits : std::char_traits { - using char_type = signed char; + using char_type = unsigned char; + using int_type = unsigned long; + + // Redefine to_int_type function + static int_type to_int_type(char_type c) + { + return static_cast(c); + } }; // Explicitly define char traits for signed char since it is not standard template<> struct char_traits : std::char_traits { - using char_type = unsigned char; + using char_type = signed char; }; // General-purpose iterator-based adapter. It might not be as fast as