mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-06 13:41:35 +01:00
Assert that String() and Key() are given null-terminated strings
Assert in case users attempt to pass a char array to String() or Key() that is not null terminated; that is not the intended use of the API. Null terminate your string buffers.
This commit is contained in:
parent
61f8c4ef0d
commit
cdea825a0b
@ -193,9 +193,15 @@ public:
|
||||
|
||||
//! The compiler can give us the length of quoted strings for free.
|
||||
template <typename T, size_t N>
|
||||
bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return String(str, N-1); }
|
||||
bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) {
|
||||
RAPIDJSON_ASSERT(str[N-1] == '\0'); // you must pass in a null-terminated string (quoted constant strings are always null-terminated)
|
||||
return String(str, N-1);
|
||||
}
|
||||
template <typename T, size_t N>
|
||||
bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return Key(str, N-1); }
|
||||
bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) {
|
||||
RAPIDJSON_ASSERT(str[N-1] == '\0'); // you must pass in a null-terminated string (quoted constant strings are always null-terminated)
|
||||
return Key(str, N-1);
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
|
@ -257,9 +257,15 @@ public:
|
||||
|
||||
//! The compiler can give us the length of quoted strings for free.
|
||||
template <typename T, size_t N>
|
||||
bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return String(str, N-1); }
|
||||
bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) {
|
||||
RAPIDJSON_ASSERT(str[N-1] == '\0'); // you must pass in a null-terminated string (quoted constant strings are always null-terminated)
|
||||
return String(str, N-1);
|
||||
}
|
||||
template <typename T, size_t N>
|
||||
bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return Key(str, N-1); }
|
||||
bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) {
|
||||
RAPIDJSON_ASSERT(str[N-1] == '\0'); // you must pass in a null-terminated string (quoted constant strings are always null-terminated)
|
||||
return Key(str, N-1);
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user