From 0f9dbe0a9c78b6a8163e47a4b5e1c5df7a3360b9 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 29 Aug 2016 10:17:57 +0800 Subject: [PATCH 1/2] Defer thread creation in parsebypart example --- example/parsebyparts/parsebyparts.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example/parsebyparts/parsebyparts.cpp b/example/parsebyparts/parsebyparts.cpp index 57eed005d..a377efd4e 100644 --- a/example/parsebyparts/parsebyparts.cpp +++ b/example/parsebyparts/parsebyparts.cpp @@ -21,12 +21,15 @@ class AsyncDocumentParser { AsyncDocumentParser(Document& d) : stream_(*this) , d_(d) - , parseThread_(&AsyncDocumentParser::Parse, this) + , parseThread_() , mutex_() , notEmpty_() , finish_() , completed_() - {} + { + // Create and execute thread after all member variables are initialized. + parseThread_ = std::thread(&AsyncDocumentParser::Parse, this); + } ~AsyncDocumentParser() { if (!parseThread_.joinable()) From 3e2172bd52308bc57db0b5930347ce451b6cc0f8 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 3 Sep 2016 23:37:00 +0800 Subject: [PATCH 2/2] Add preconditions in writer and string functions --- include/rapidjson/internal/strfunc.h | 3 +++ include/rapidjson/prettywriter.h | 8 +++++++- include/rapidjson/writer.h | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/internal/strfunc.h b/include/rapidjson/internal/strfunc.h index 2edfae526..de41d8f9c 100644 --- a/include/rapidjson/internal/strfunc.h +++ b/include/rapidjson/internal/strfunc.h @@ -28,6 +28,7 @@ namespace internal { */ template inline SizeType StrLen(const Ch* s) { + RAPIDJSON_ASSERT(s != 0); const Ch* p = s; while (*p) ++p; return SizeType(p - s); @@ -36,6 +37,8 @@ inline SizeType StrLen(const Ch* s) { //! Returns number of code points in a encoded string. template bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { + RAPIDJSON_ASSERT(s != 0); + RAPIDJSON_ASSERT(outCount != 0); GenericStringStream is(s); const typename Encoding::Ch* end = s + length; SizeType count = 0; diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 0dcb0fee9..c6f0216e9 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -91,12 +91,14 @@ class PrettyWriter : public Writer