From 377995f4956f99c671bc97894eb0141182b08a56 Mon Sep 17 00:00:00 2001 From: Francois Chabot Date: Wed, 27 May 2020 18:21:38 -0400 Subject: [PATCH] forcefully exclude arrays from being interpreted as pointers --- .../nlohmann/detail/input/input_adapters.hpp | 18 ++++++++++++------ single_include/nlohmann/json.hpp | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 67a7f0d0..0a52abaa 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -391,12 +391,13 @@ inline input_stream_adapter input_adapter(std::istream&& stream) using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval(), std::declval())); // Null-delimited strings, and the like. -template::value and - std::is_integral::type>::value and - sizeof(typename std::remove_pointer::type) == 1, - int>::type = 0> +template < typename CharT, + typename std::enable_if < + std::is_pointer::value and + !std::is_array::value and + std::is_integral::type>::value and + sizeof(typename std::remove_pointer::type) == 1, + int >::type = 0 > contiguous_bytes_input_adapter input_adapter(CharT b) { auto length = std::strlen(reinterpret_cast(b)); @@ -404,6 +405,11 @@ contiguous_bytes_input_adapter input_adapter(CharT b) return input_adapter(ptr, ptr + length); } +template +auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) +{ + return input_adapter(array, array + N); +} // This class only handles inputs of input_buffer_adapter type. // It's required so that expressions like {ptr, len} can be implicitely casted diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 5240aedd..5e8e23fe 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4813,12 +4813,13 @@ inline input_stream_adapter input_adapter(std::istream&& stream) using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval(), std::declval())); // Null-delimited strings, and the like. -template::value and - std::is_integral::type>::value and - sizeof(typename std::remove_pointer::type) == 1, - int>::type = 0> +template < typename CharT, + typename std::enable_if < + std::is_pointer::value and + !std::is_array::value and + std::is_integral::type>::value and + sizeof(typename std::remove_pointer::type) == 1, + int >::type = 0 > contiguous_bytes_input_adapter input_adapter(CharT b) { auto length = std::strlen(reinterpret_cast(b)); @@ -4826,6 +4827,11 @@ contiguous_bytes_input_adapter input_adapter(CharT b) return input_adapter(ptr, ptr + length); } +template +auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) +{ + return input_adapter(array, array + N); +} // This class only handles inputs of input_buffer_adapter type. // It's required so that expressions like {ptr, len} can be implicitely casted