From ca2125639515fccd33573f7776db63ab13392a2e Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Fri, 23 Mar 2007 07:05:19 +0000 Subject: [PATCH] setComment() will assert if comment does not start with / (or if it were NULL, which would have seg-faulted before). --- include/json/value.h | 2 ++ src/lib_json/json_value.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/json/value.h b/include/json/value.h index fe2f9eb..19e2966 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -317,8 +317,10 @@ namespace Json { // EnumValues enumValues() const; //# endif + /// Comments must be //... or /* ... */ void setComment( const char *comment, CommentPlacement placement ); + /// Comments must be //... or /* ... */ void setComment( const std::string &comment, CommentPlacement placement ); bool hasComment( CommentPlacement placement ) const; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index b3e90b6..0fb735f 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -149,6 +150,9 @@ Value::CommentInfo::setComment( const char *text ) { if ( comment_ ) valueAllocator()->releaseStringValue( comment_ ); + JSON_ASSERT( text ); + JSON_ASSERT_MESSAGE( text[0]==NULL || text[0]=='/', "Comments must start with /"); + // It seems that /**/ style comments are acceptable as well. comment_ = valueAllocator()->duplicateStringValue( text ); }