setComment() will assert if comment does not start with / (or if it were NULL, which would have seg-faulted before).

This commit is contained in:
Christopher Dunn 2007-03-23 07:05:19 +00:00
parent 8386d3efe1
commit ca21256395
2 changed files with 6 additions and 0 deletions

View File

@ -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;

View File

@ -1,3 +1,4 @@
#include <iostream>
#include <json/value.h>
#include <json/writer.h>
#include <utility>
@ -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 );
}