Skip to content

Commit ca21256

Browse files
committed
setComment() will assert if comment does not start with / (or if it were NULL, which would have seg-faulted before).
1 parent 8386d3e commit ca21256

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

include/json/value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ namespace Json {
317317
// EnumValues enumValues() const;
318318
//# endif
319319

320+
/// Comments must be //... or /* ... */
320321
void setComment( const char *comment,
321322
CommentPlacement placement );
323+
/// Comments must be //... or /* ... */
322324
void setComment( const std::string &comment,
323325
CommentPlacement placement );
324326
bool hasComment( CommentPlacement placement ) const;

src/lib_json/json_value.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <iostream>
12
#include <json/value.h>
23
#include <json/writer.h>
34
#include <utility>
@@ -149,6 +150,9 @@ Value::CommentInfo::setComment( const char *text )
149150
{
150151
if ( comment_ )
151152
valueAllocator()->releaseStringValue( comment_ );
153+
JSON_ASSERT( text );
154+
JSON_ASSERT_MESSAGE( text[0]==NULL || text[0]=='/', "Comments must start with /");
155+
// It seems that /**/ style comments are acceptable as well.
152156
comment_ = valueAllocator()->duplicateStringValue( text );
153157
}
154158

0 commit comments

Comments
 (0)