Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Stiles <johnstiles@gmail.com>2017-03-05 20:23:03 +0300
committerJohn Stiles <johnstiles@gmail.com>2017-03-05 20:23:03 +0300
commitcdea825a0bc81531d2cd2758362b606106373477 (patch)
tree447c171ee61fc7d39f4ab2837b740ff19758e23b /include/rapidjson/prettywriter.h
parent61f8c4ef0df9d91fe6a684bb1b1572e0a537f66e (diff)
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.
Diffstat (limited to 'include/rapidjson/prettywriter.h')
-rw-r--r--include/rapidjson/prettywriter.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h
index 64301b8d..abea4048 100644
--- a/include/rapidjson/prettywriter.h
+++ b/include/rapidjson/prettywriter.h
@@ -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);
+ }
//@}