Skip to content

Commit f64244e

Browse files
committed
COMP: Use nullptr instead of 0 or NULL
The check converts the usage of null pointer constants (eg. NULL, 0) to use the new C++11 nullptr keyword. SRCDIR=/Users/johnsonhj/src/jsoncpp #My local SRC BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/ run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-nullptr -header-filter=.* -fix
1 parent 6219eae commit f64244e

File tree

7 files changed

+46
-46
lines changed

7 files changed

+46
-46
lines changed

include/json/reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class JSON_API Reader {
221221
Location end,
222222
unsigned int& unicode);
223223
bool
224-
addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
224+
addError(const JSONCPP_STRING& message, Token& token, Location extra = nullptr);
225225
bool recoverFromError(TokenType skipUntilToken);
226226
bool addErrorAndRecover(const JSONCPP_STRING& message,
227227
Token& token,

src/lib_json/json_reader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ bool Reader::parse(const char* beginDoc,
137137
end_ = endDoc;
138138
collectComments_ = collectComments;
139139
current_ = begin_;
140-
lastValueEnd_ = 0;
141-
lastValue_ = 0;
140+
lastValueEnd_ = nullptr;
141+
lastValue_ = nullptr;
142142
commentsBefore_.clear();
143143
errors_.clear();
144144
while (!nodes_.empty())
@@ -394,7 +394,7 @@ void Reader::addComment(Location begin,
394394
assert(collectComments_);
395395
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
396396
if (placement == commentAfterOnSameLine) {
397-
assert(lastValue_ != 0);
397+
assert(lastValue_ != nullptr);
398398
lastValue_->setComment(normalized, placement);
399399
} else {
400400
commentsBefore_ += normalized;
@@ -862,7 +862,7 @@ bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
862862
ErrorInfo info;
863863
info.token_ = token;
864864
info.message_ = message;
865-
info.extra_ = 0;
865+
info.extra_ = nullptr;
866866
errors_.push_back(info);
867867
return true;
868868
}
@@ -1002,7 +1002,7 @@ class OurReader {
10021002
Location end,
10031003
unsigned int& unicode);
10041004
bool
1005-
addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
1005+
addError(const JSONCPP_STRING& message, Token& token, Location extra = nullptr);
10061006
bool recoverFromError(TokenType skipUntilToken);
10071007
bool addErrorAndRecover(const JSONCPP_STRING& message,
10081008
Token& token,
@@ -1061,8 +1061,8 @@ bool OurReader::parse(const char* beginDoc,
10611061
end_ = endDoc;
10621062
collectComments_ = collectComments;
10631063
current_ = begin_;
1064-
lastValueEnd_ = 0;
1065-
lastValue_ = 0;
1064+
lastValueEnd_ = nullptr;
1065+
lastValue_ = nullptr;
10661066
commentsBefore_.clear();
10671067
errors_.clear();
10681068
while (!nodes_.empty())
@@ -1368,7 +1368,7 @@ void OurReader::addComment(Location begin,
13681368
assert(collectComments_);
13691369
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
13701370
if (placement == commentAfterOnSameLine) {
1371-
assert(lastValue_ != 0);
1371+
assert(lastValue_ != nullptr);
13721372
lastValue_->setComment(normalized, placement);
13731373
} else {
13741374
commentsBefore_ += normalized;
@@ -1877,7 +1877,7 @@ bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
18771877
ErrorInfo info;
18781878
info.token_ = token;
18791879
info.message_ = message;
1880-
info.extra_ = 0;
1880+
info.extra_ = nullptr;
18811881
errors_.push_back(info);
18821882
return true;
18831883
}

src/lib_json/json_value.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline char* duplicateStringValue(const char* value, size_t length) {
108108
length = Value::maxInt - 1;
109109

110110
char* newString = static_cast<char*>(malloc(length + 1));
111-
if (newString == NULL) {
111+
if (newString == nullptr) {
112112
throwRuntimeError("in Json::Value::duplicateStringValue(): "
113113
"Failed to allocate string value buffer");
114114
}
@@ -129,7 +129,7 @@ static inline char* duplicateAndPrefixStringValue(const char* value,
129129
"length too big for prefixing");
130130
unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
131131
char* newString = static_cast<char*>(malloc(actualLength));
132-
if (newString == 0) {
132+
if (newString == nullptr) {
133133
throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
134134
"Failed to allocate string value buffer");
135135
}
@@ -210,7 +210,7 @@ JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
210210
// //////////////////////////////////////////////////////////////////
211211
// //////////////////////////////////////////////////////////////////
212212

213-
Value::CommentInfo::CommentInfo() : comment_(0) {}
213+
Value::CommentInfo::CommentInfo() : comment_(nullptr) {}
214214

215215
Value::CommentInfo::~CommentInfo() {
216216
if (comment_)
@@ -220,9 +220,9 @@ Value::CommentInfo::~CommentInfo() {
220220
void Value::CommentInfo::setComment(const char* text, size_t len) {
221221
if (comment_) {
222222
releaseStringValue(comment_, 0u);
223-
comment_ = 0;
223+
comment_ = nullptr;
224224
}
225-
JSON_ASSERT(text != 0);
225+
JSON_ASSERT(text != nullptr);
226226
JSON_ASSERT_MESSAGE(
227227
text[0] == '\0' || text[0] == '/',
228228
"in Json::Value::setComment(): Comments must start with /");
@@ -241,7 +241,7 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
241241
// Notes: policy_ indicates if the string was allocated when
242242
// a string is stored.
243243

244-
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
244+
Value::CZString::CZString(ArrayIndex index) : cstr_(nullptr), index_(index) {}
245245

246246
Value::CZString::CZString(char const* str,
247247
unsigned length,
@@ -253,7 +253,7 @@ Value::CZString::CZString(char const* str,
253253
}
254254

255255
Value::CZString::CZString(const CZString& other) {
256-
cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ != 0
256+
cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ != nullptr
257257
? duplicateStringValue(other.cstr_, other.storage_.length_)
258258
: other.cstr_);
259259
storage_.policy_ =
@@ -413,7 +413,7 @@ Value::Value(double value) {
413413

414414
Value::Value(const char* value) {
415415
initBasic(stringValue, true);
416-
JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor");
416+
JSON_ASSERT_MESSAGE(value != nullptr, "Null Value Passed to Value Constructor");
417417
value_.string_ = duplicateAndPrefixStringValue(
418418
value, static_cast<unsigned>(strlen(value)));
419419
}
@@ -528,7 +528,7 @@ bool Value::operator<(const Value& other) const {
528528
case booleanValue:
529529
return value_.bool_ < other.value_.bool_;
530530
case stringValue: {
531-
if ((value_.string_ == 0) || (other.value_.string_ == 0)) {
531+
if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) {
532532
if (other.value_.string_)
533533
return true;
534534
else
@@ -590,7 +590,7 @@ bool Value::operator==(const Value& other) const {
590590
case booleanValue:
591591
return value_.bool_ == other.value_.bool_;
592592
case stringValue: {
593-
if ((value_.string_ == 0) || (other.value_.string_ == 0)) {
593+
if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) {
594594
return (value_.string_ == other.value_.string_);
595595
}
596596
unsigned this_len;
@@ -622,8 +622,8 @@ bool Value::operator!=(const Value& other) const { return !(*this == other); }
622622
const char* Value::asCString() const {
623623
JSON_ASSERT_MESSAGE(type_ == stringValue,
624624
"in Json::Value::asCString(): requires stringValue");
625-
if (value_.string_ == 0)
626-
return 0;
625+
if (value_.string_ == nullptr)
626+
return nullptr;
627627
unsigned this_len;
628628
char const* this_str;
629629
decodePrefixedString(this->allocated_, this->value_.string_, &this_len,
@@ -648,7 +648,7 @@ unsigned Value::getCStringLength() const {
648648
bool Value::getString(char const** begin, char const** end) const {
649649
if (type_ != stringValue)
650650
return false;
651-
if (value_.string_ == 0)
651+
if (value_.string_ == nullptr)
652652
return false;
653653
unsigned length;
654654
decodePrefixedString(this->allocated_, this->value_.string_, &length, begin);
@@ -661,7 +661,7 @@ JSONCPP_STRING Value::asString() const {
661661
case nullValue:
662662
return "";
663663
case stringValue: {
664-
if (value_.string_ == 0)
664+
if (value_.string_ == nullptr)
665665
return "";
666666
unsigned this_len;
667667
char const* this_str;
@@ -1006,7 +1006,7 @@ const Value& Value::operator[](int index) const {
10061006
void Value::initBasic(ValueType type, bool allocated) {
10071007
type_ = type;
10081008
allocated_ = allocated;
1009-
comments_ = 0;
1009+
comments_ = nullptr;
10101010
start_ = 0;
10111011
limit_ = 0;
10121012
}
@@ -1073,7 +1073,7 @@ void Value::dupMeta(const Value& other) {
10731073
strlen(otherComment.comment_));
10741074
}
10751075
} else {
1076-
comments_ = 0;
1076+
comments_ = nullptr;
10771077
}
10781078
start_ = other.start_;
10791079
limit_ = other.limit_;
@@ -1131,12 +1131,12 @@ Value const* Value::find(char const* begin, char const* end) const {
11311131
"in Json::Value::find(key, end, found): requires "
11321132
"objectValue or nullValue");
11331133
if (type_ == nullValue)
1134-
return NULL;
1134+
return nullptr;
11351135
CZString actualKey(begin, static_cast<unsigned>(end - begin),
11361136
CZString::noDuplication);
11371137
ObjectValues::const_iterator it = value_.map_->find(actualKey);
11381138
if (it == value_.map_->end())
1139-
return NULL;
1139+
return nullptr;
11401140
return &(*it).second;
11411141
}
11421142
const Value& Value::operator[](const char* key) const {
@@ -1267,7 +1267,7 @@ Value Value::get(const CppTL::ConstString& key,
12671267

12681268
bool Value::isMember(char const* begin, char const* end) const {
12691269
Value const* value = find(begin, end);
1270-
return NULL != value;
1270+
return nullptr != value;
12711271
}
12721272
bool Value::isMember(char const* key) const {
12731273
return isMember(key, key + strlen(key));
@@ -1470,7 +1470,7 @@ void Value::setComment(const JSONCPP_STRING& comment,
14701470
}
14711471

14721472
bool Value::hasComment(CommentPlacement placement) const {
1473-
return comments_ != 0 && comments_[placement].comment_ != 0;
1473+
return comments_ != nullptr && comments_[placement].comment_ != nullptr;
14741474
}
14751475

14761476
JSONCPP_STRING Value::getComment(CommentPlacement placement) const {

src/lib_json/json_valueiterator.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ char const* ValueIteratorBase::memberName() const {
108108
char const* ValueIteratorBase::memberName(char const** end) const {
109109
const char* cname = (*current_).first.data();
110110
if (!cname) {
111-
*end = NULL;
112-
return NULL;
111+
*end = nullptr;
112+
return nullptr;
113113
}
114114
*end = cname + (*current_).first.length();
115115
return cname;

src/lib_json/json_writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static JSONCPP_STRING toHex16Bit(unsigned int x) {
275275
}
276276

277277
static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
278-
if (value == NULL)
278+
if (value == nullptr)
279279
return "";
280280

281281
if (!isAnyCharRequiredQuoting(value, length))
@@ -646,7 +646,7 @@ bool StyledWriter::hasCommentForValue(const Value& value) {
646646
// //////////////////////////////////////////////////////////////////
647647

648648
StyledStreamWriter::StyledStreamWriter(const JSONCPP_STRING& indentation)
649-
: document_(NULL), rightMargin_(74), indentation_(indentation),
649+
: document_(nullptr), rightMargin_(74), indentation_(indentation),
650650
addChildValues_(), indented_(false) {}
651651

652652
void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
@@ -661,7 +661,7 @@ void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
661661
writeValue(root);
662662
writeCommentAfterValueOnSameLine(root);
663663
*document_ << "\n";
664-
document_ = NULL; // Forget the stream, for safety.
664+
document_ = nullptr; // Forget the stream, for safety.
665665
}
666666

667667
void StyledStreamWriter::writeValue(const Value& value) {
@@ -940,7 +940,7 @@ int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) {
940940
writeValue(root);
941941
writeCommentAfterValueOnSameLine(root);
942942
*sout_ << endingLineFeedSymbol_;
943-
sout_ = NULL;
943+
sout_ = nullptr;
944944
return 0;
945945
}
946946
void BuiltStyledStreamWriter::writeValue(Value const& value) {
@@ -1158,7 +1158,7 @@ bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) {
11581158
///////////////
11591159
// StreamWriter
11601160

1161-
StreamWriter::StreamWriter() : sout_(NULL) {}
1161+
StreamWriter::StreamWriter() : sout_(nullptr) {}
11621162
StreamWriter::~StreamWriter() {}
11631163
StreamWriter::Factory::~Factory() {}
11641164
StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); }

src/test_lib_json/jsontest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ namespace JsonTest {
7474
// //////////////////////////////////////////////////////////////////
7575

7676
TestResult::TestResult()
77-
: predicateId_(1), lastUsedPredicateId_(0), messageTarget_(0) {
77+
: predicateId_(1), lastUsedPredicateId_(0), messageTarget_(nullptr) {
7878
// The root predicate has id 0
7979
rootPredicateNode_.id_ = 0;
80-
rootPredicateNode_.next_ = 0;
80+
rootPredicateNode_.next_ = nullptr;
8181
predicateStackTail_ = &rootPredicateNode_;
8282
}
8383

@@ -89,7 +89,7 @@ TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
8989
/// added.
9090
unsigned int nestingLevel = 0;
9191
PredicateContext* lastNode = rootPredicateNode_.next_;
92-
for (; lastNode != 0; lastNode = lastNode->next_) {
92+
for (; lastNode != nullptr; lastNode = lastNode->next_) {
9393
if (lastNode->id_ > lastUsedPredicateId_) // new PredicateContext
9494
{
9595
lastUsedPredicateId_ = lastNode->id_;
@@ -124,17 +124,17 @@ void TestResult::addFailureInfo(const char* file,
124124

125125
TestResult& TestResult::popPredicateContext() {
126126
PredicateContext* lastNode = &rootPredicateNode_;
127-
while (lastNode->next_ != 0 && lastNode->next_->next_ != 0) {
127+
while (lastNode->next_ != nullptr && lastNode->next_->next_ != nullptr) {
128128
lastNode = lastNode->next_;
129129
}
130130
// Set message target to popped failure
131131
PredicateContext* tail = lastNode->next_;
132-
if (tail != 0 && tail->failure_ != 0) {
132+
if (tail != nullptr && tail->failure_ != nullptr) {
133133
messageTarget_ = tail->failure_;
134134
}
135135
// Remove tail from list
136136
predicateStackTail_ = lastNode;
137-
lastNode->next_ = 0;
137+
lastNode->next_ = nullptr;
138138
return *this;
139139
}
140140

@@ -186,7 +186,7 @@ JSONCPP_STRING TestResult::indentText(const JSONCPP_STRING& text,
186186
}
187187

188188
TestResult& TestResult::addToLastFailure(const JSONCPP_STRING& message) {
189-
if (messageTarget_ != 0) {
189+
if (messageTarget_ != nullptr) {
190190
messageTarget_->message_ += message;
191191
}
192192
return *this;
@@ -207,7 +207,7 @@ TestResult& TestResult::operator<<(bool value) {
207207
// class TestCase
208208
// //////////////////////////////////////////////////////////////////
209209

210-
TestCase::TestCase() : result_(0) {}
210+
TestCase::TestCase() : result_(nullptr) {}
211211

212212
TestCase::~TestCase() {}
213213

src/test_lib_json/jsontest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TestResult {
6969

7070
/// Adds an assertion failure.
7171
TestResult&
72-
addFailure(const char* file, unsigned int line, const char* expr = 0);
72+
addFailure(const char* file, unsigned int line, const char* expr = nullptr);
7373

7474
/// Removes the last PredicateContext added to the predicate stack
7575
/// chained list.

0 commit comments

Comments
 (0)