diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 64301b8..abea404 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 - bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { return String(str, N-1); } + bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { + 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 - bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { return Key(str, N-1); } + bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { + 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); + } //@} diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 755f483..c438f71 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -257,9 +257,15 @@ public: //! The compiler can give us the length of quoted strings for free. template - bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { return String(str, N-1); } + bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { + 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 - bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { return Key(str, N-1); } + bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { + 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); + } //@}