Fixed deserializeJson() silently accepting a Stream* (issue #978)

This commit is contained in:
Benoit Blanchon
2019-05-09 08:33:09 +02:00
parent eaf55e174b
commit 2af003e4e2
5 changed files with 52 additions and 3 deletions

View File

@ -6,6 +6,16 @@
namespace ARDUINOJSON_NAMESPACE {
template <typename T>
struct IsCharOrVoid {
static const bool value =
is_same<T, void>::value || is_same<T, char>::value ||
is_same<T, unsigned char>::value || is_same<T, signed char>::value;
};
template <typename T>
struct IsCharOrVoid<const T> : IsCharOrVoid<T> {};
class UnsafeCharPointerReader {
const char* _ptr;
@ -41,12 +51,16 @@ class SafeCharPointerReader {
};
template <typename TChar>
inline UnsafeCharPointerReader makeReader(TChar* input) {
inline typename enable_if<IsCharOrVoid<TChar>::value,
UnsafeCharPointerReader>::type
makeReader(TChar* input) {
return UnsafeCharPointerReader(reinterpret_cast<const char*>(input));
}
template <typename TChar>
inline SafeCharPointerReader makeReader(TChar* input, size_t n) {
inline
typename enable_if<IsCharOrVoid<TChar>::value, SafeCharPointerReader>::type
makeReader(TChar* input, size_t n) {
return SafeCharPointerReader(reinterpret_cast<const char*>(input), n);
}