summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorA. Jesse Jiryu Davis <jesse@mongodb.com>2019-06-14 16:42:10 -0400
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2019-06-14 19:23:18 -0400
commit47b380f03e8898f4706ff01fa2be64dfb72e0dba (patch)
treefb3508758c9abd0e297afee43ac847bf5aebcbbb /src/mongo/bson
parentb3c26131f6ab3f919beca658341e737de5d45683 (diff)
downloadmongo-47b380f03e8898f4706ff01fa2be64dfb72e0dba.tar.gz
SERVER-41071 Replace NULL and 0 with nullptr
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/bson_validate.cpp2
-rw-r--r--src/mongo/bson/bson_validate_test.cpp2
-rw-r--r--src/mongo/bson/bsonelement.cpp2
-rw-r--r--src/mongo/bson/bsonmisc.h4
-rw-r--r--src/mongo/bson/bsonobj.h2
-rw-r--r--src/mongo/bson/bsonobjbuilder.cpp2
-rw-r--r--src/mongo/bson/bsonobjbuilder.h10
-rw-r--r--src/mongo/bson/json.cpp8
-rw-r--r--src/mongo/bson/json.h4
-rw-r--r--src/mongo/bson/mutable/const_element.h2
-rw-r--r--src/mongo/bson/mutable/document.cpp6
-rw-r--r--src/mongo/bson/mutable/document.h2
-rw-r--r--src/mongo/bson/mutable/element.h4
-rw-r--r--src/mongo/bson/mutable/mutable_bson_test.cpp34
-rw-r--r--src/mongo/bson/oid.cpp2
-rw-r--r--src/mongo/bson/util/builder.h3
-rw-r--r--src/mongo/bson/util/builder_test.cpp2
17 files changed, 47 insertions, 44 deletions
diff --git a/src/mongo/bson/bson_validate.cpp b/src/mongo/bson/bson_validate.cpp
index da7f1de0c1c..40edd405c9b 100644
--- a/src/mongo/bson/bson_validate.cpp
+++ b/src/mongo/bson/bson_validate.cpp
@@ -309,7 +309,7 @@ Status validateElementInfo(Buffer* buffer,
Status validateBSONIterative(Buffer* buffer) {
std::vector<ValidationObjectFrame> frames;
frames.reserve(16);
- ValidationObjectFrame* curr = NULL;
+ ValidationObjectFrame* curr = nullptr;
ValidationState::State state = ValidationState::BeginObj;
uint64_t idElemStartPos = 0; // will become idElem once validated
diff --git a/src/mongo/bson/bson_validate_test.cpp b/src/mongo/bson/bson_validate_test.cpp
index 2c3a9b0d07b..94fb4ec269b 100644
--- a/src/mongo/bson/bson_validate_test.cpp
+++ b/src/mongo/bson/bson_validate_test.cpp
@@ -146,7 +146,7 @@ TEST(BSONValidate, MuckingData1) {
}
TEST(BSONValidate, Fuzz) {
- int64_t seed = time(0);
+ int64_t seed = time(nullptr);
log() << "BSONValidate Fuzz random seed: " << seed << endl;
PseudoRandom randomSource(seed);
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 2ad980eb957..d659f84ee13 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -160,7 +160,7 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
s << " ";
}
- if (strtol(e.fieldName(), 0, 10) > count) {
+ if (strtol(e.fieldName(), nullptr, 10) > count) {
s << "undefined";
} else {
e.jsonStringStream(format, false, pretty ? pretty + 1 : 0, s);
diff --git a/src/mongo/bson/bsonmisc.h b/src/mongo/bson/bsonmisc.h
index 6baec67d7a6..cfc56a63ef2 100644
--- a/src/mongo/bson/bsonmisc.h
+++ b/src/mongo/bson/bsonmisc.h
@@ -212,7 +212,7 @@ public:
void endField(StringData nextFieldName = StringData());
bool subobjStarted() const {
- return _fieldName != 0;
+ return _fieldName != nullptr;
}
// The following methods provide API compatibility with BSONArrayBuilder
@@ -236,7 +236,7 @@ private:
BSONObjBuilder* _builder;
bool haveSubobj() const {
- return _subobj.get() != 0;
+ return _subobj.get() != nullptr;
}
BSONObjBuilder* subobj();
std::unique_ptr<BSONObjBuilder> _subobj;
diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h
index 2faa7c9cc09..c79615bbb94 100644
--- a/src/mongo/bson/bsonobj.h
+++ b/src/mongo/bson/bsonobj.h
@@ -697,7 +697,7 @@ public:
explicit BSONObjIterator(const BSONObj& jso) {
int sz = jso.objsize();
if (MONGO_unlikely(sz == 0)) {
- _pos = _theend = 0;
+ _pos = _theend = nullptr;
return;
}
_pos = jso.objdata() + 4;
diff --git a/src/mongo/bson/bsonobjbuilder.cpp b/src/mongo/bson/bsonobjbuilder.cpp
index 7c64e35cac5..871dcdfb1c0 100644
--- a/src/mongo/bson/bsonobjbuilder.cpp
+++ b/src/mongo/bson/bsonobjbuilder.cpp
@@ -90,7 +90,7 @@ BSONObjBuilder& BSONObjBuilder::appendMinForType(StringData fieldName, int t) {
appendArray(fieldName, BSONObj());
return *this;
case BinData:
- appendBinData(fieldName, 0, BinDataGeneral, (const char*)0);
+ appendBinData(fieldName, 0, BinDataGeneral, (const char*)nullptr);
return *this;
case RegEx:
appendRegex(fieldName, "");
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index ef28c9d828a..fe8c0a5b555 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -68,7 +68,7 @@ class BSONObjBuilder {
public:
/** @param initsize this is just a hint as to the final size of the object */
BSONObjBuilder(int initsize = 512)
- : _b(_buf), _buf(initsize), _offset(0), _s(this), _tracker(0), _doneCalled(false) {
+ : _b(_buf), _buf(initsize), _offset(0), _s(this), _tracker(nullptr), _doneCalled(false) {
// Skip over space for the object length. The length is filled in by _done.
_b.skip(sizeof(int));
@@ -85,7 +85,7 @@ public:
_buf(0),
_offset(baseBuilder.len()),
_s(this),
- _tracker(0),
+ _tracker(nullptr),
_doneCalled(false) {
// Skip over space for the object length, which is filled in by _done. We don't need a
// holder since we are a sub-builder, and some parent builder has already made the
@@ -135,7 +135,7 @@ public:
* into this constructor where possible.
*/
BSONObjBuilder(BSONObj prefix)
- : _b(_buf), _buf(0), _offset(0), _s(this), _tracker(0), _doneCalled(false) {
+ : _b(_buf), _buf(0), _offset(0), _s(this), _tracker(nullptr), _doneCalled(false) {
// If prefix wasn't owned or we don't have exclusive access to it, we must copy.
if (!prefix.isOwned() || prefix.sharedBuffer().isShared()) {
_b.grow(prefix.objsize()); // Make sure we won't need to realloc().
@@ -386,7 +386,9 @@ public:
@deprecated Generally, it is preferred to use the append append(name, oid)
method for this.
*/
- BSONObjBuilder& appendOID(StringData fieldName, OID* oid = 0, bool generateIfBlank = false) {
+ BSONObjBuilder& appendOID(StringData fieldName,
+ OID* oid = nullptr,
+ bool generateIfBlank = false) {
_b.appendNum((char)jstOID);
_b.appendStr(fieldName);
if (oid)
diff --git a/src/mongo/bson/json.cpp b/src/mongo/bson/json.cpp
index a2bc9872c79..15661b0a456 100644
--- a/src/mongo/bson/json.cpp
+++ b/src/mongo/bson/json.cpp
@@ -1108,7 +1108,7 @@ Status JParse::chars(std::string* result, const char* terminalSet, const char* a
const char* q = _input;
while (q < _input_end && !match(*q, terminalSet)) {
MONGO_JSON_DEBUG("q: " << q);
- if (allowedSet != NULL) {
+ if (allowedSet != nullptr) {
if (!match(*q, allowedSet)) {
_input = q;
return Status::OK();
@@ -1226,7 +1226,7 @@ inline bool JParse::readToken(const char* token) {
bool JParse::readTokenImpl(const char* token, bool advance) {
MONGO_JSON_DEBUG("token: " << token);
const char* check = _input;
- if (token == NULL) {
+ if (token == nullptr) {
return false;
}
// 'isspace()' takes an 'int' (signed), so (default signed) 'char's get sign-extended
@@ -1264,13 +1264,13 @@ bool JParse::readField(StringData expectedField) {
}
inline bool JParse::match(char matchChar, const char* matchSet) const {
- if (matchSet == NULL) {
+ if (matchSet == nullptr) {
return true;
}
if (*matchSet == '\0') {
return false;
}
- return (strchr(matchSet, matchChar) != NULL);
+ return (strchr(matchSet, matchChar) != nullptr);
}
bool JParse::isHexString(StringData str) const {
diff --git a/src/mongo/bson/json.h b/src/mongo/bson/json.h
index 38217fb7eef..45b08acd095 100644
--- a/src/mongo/bson/json.h
+++ b/src/mongo/bson/json.h
@@ -52,7 +52,7 @@ namespace mongo {
BSONObj fromjson(const std::string& str);
/** @param len will be size of JSON object in text chars. */
-BSONObj fromjson(const char* str, int* len = NULL);
+BSONObj fromjson(const char* str, int* len = nullptr);
/**
* Tests whether the JSON string is an Array.
@@ -410,7 +410,7 @@ private:
* string, but there is no guarantee that it will not contain other
* null characters.
*/
- Status chars(std::string* result, const char* terminalSet, const char* allowedSet = NULL);
+ Status chars(std::string* result, const char* terminalSet, const char* allowedSet = nullptr);
/**
* Converts the two byte Unicode code point to its UTF8 character
diff --git a/src/mongo/bson/mutable/const_element.h b/src/mongo/bson/mutable/const_element.h
index 4b8d483095e..5346c56c52d 100644
--- a/src/mongo/bson/mutable/const_element.h
+++ b/src/mongo/bson/mutable/const_element.h
@@ -120,7 +120,7 @@ private:
friend class Document;
template <typename Builder>
- inline void writeElement(Builder* builder, const StringData* fieldName = NULL) const;
+ inline void writeElement(Builder* builder, const StringData* fieldName = nullptr) const;
Element _basis;
};
diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp
index fb75d2d008c..443c57cebf1 100644
--- a/src/mongo/bson/mutable/document.cpp
+++ b/src/mongo/bson/mutable/document.cpp
@@ -997,7 +997,7 @@ public:
// inform upstream that we are not returning in-place result data.
if (_inPlaceMode == Document::kInPlaceDisabled) {
damages->clear();
- *source = NULL;
+ *source = nullptr;
if (size)
*size = 0;
return false;
@@ -1077,7 +1077,7 @@ public:
template <typename Builder>
void writeElement(Element::RepIdx repIdx,
Builder* builder,
- const StringData* fieldName = NULL) const;
+ const StringData* fieldName = nullptr) const;
template <typename Builder>
void writeChildren(Element::RepIdx repIdx, Builder* builder) const;
@@ -2647,7 +2647,7 @@ Element Document::makeElementSafeNum(StringData fieldName, SafeNum value) {
}
Element Document::makeElement(ConstElement element) {
- return makeElement(element, NULL);
+ return makeElement(element, nullptr);
}
Element Document::makeElementWithNewFieldName(StringData fieldName, ConstElement element) {
diff --git a/src/mongo/bson/mutable/document.h b/src/mongo/bson/mutable/document.h
index 0feb056cc35..ac254b7ac21 100644
--- a/src/mongo/bson/mutable/document.h
+++ b/src/mongo/bson/mutable/document.h
@@ -476,7 +476,7 @@ public:
* The destination offsets in the damage events are implicitly offsets into the
* BSONObj used to construct this Document.
*/
- bool getInPlaceUpdates(DamageVector* damages, const char** source, size_t* size = NULL);
+ bool getInPlaceUpdates(DamageVector* damages, const char** source, size_t* size = nullptr);
/** Drop the queue of in-place update damage events, and do not queue new operations
* that would otherwise have been in-place. Use this if you know that in-place updates
diff --git a/src/mongo/bson/mutable/element.h b/src/mongo/bson/mutable/element.h
index 85756d1fea9..7438d97f186 100644
--- a/src/mongo/bson/mutable/element.h
+++ b/src/mongo/bson/mutable/element.h
@@ -724,7 +724,7 @@ inline bool Element::isValueMaxKey() const {
}
inline bool Element::ok() const {
- dassert(_doc != NULL);
+ dassert(_doc != nullptr);
return _repIdx <= kMaxRepIdx;
}
@@ -745,7 +745,7 @@ inline Element::RepIdx Element::getIdx() const {
}
inline Element::Element(Document* doc, RepIdx repIdx) : _doc(doc), _repIdx(repIdx) {
- dassert(_doc != NULL);
+ dassert(_doc != nullptr);
}
inline StringData Element::getValueStringOrSymbol() const {
diff --git a/src/mongo/bson/mutable/mutable_bson_test.cpp b/src/mongo/bson/mutable/mutable_bson_test.cpp
index fa13986ef12..58a46d04ce3 100644
--- a/src/mongo/bson/mutable/mutable_bson_test.cpp
+++ b/src/mongo/bson/mutable/mutable_bson_test.cpp
@@ -1017,11 +1017,11 @@ TEST(Documentation, Example2InPlaceWithDamageVector) {
// Extract the damage events
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
size_t size = 0;
ASSERT_EQUALS(true, doc.getInPlaceUpdates(&damages, &source, &size));
ASSERT_NOT_EQUALS(0U, damages.size());
- ASSERT_NOT_EQUALS(static_cast<const char*>(NULL), source);
+ ASSERT_NOT_EQUALS(static_cast<const char*>(nullptr), source);
ASSERT_NOT_EQUALS(0U, size);
apply(&obj, damages, source);
@@ -2772,12 +2772,12 @@ TEST(DocumentInPlace, InPlaceModeWorksWithNoMutations) {
mongo::BSONObj obj;
mmb::Document doc(obj, mmb::Document::kInPlaceEnabled);
ASSERT_TRUE(doc.isInPlaceModeEnabled());
- const char* source = NULL;
+ const char* source = nullptr;
mmb::DamageVector damages;
ASSERT_TRUE(damages.empty());
doc.getInPlaceUpdates(&damages, &source);
ASSERT_TRUE(damages.empty());
- ASSERT_NOT_EQUALS(static_cast<const char*>(NULL), source);
+ ASSERT_NOT_EQUALS(static_cast<const char*>(nullptr), source);
ASSERT_TRUE(doc.isInPlaceModeEnabled());
}
@@ -2876,14 +2876,14 @@ TEST(DocumentInPlace, GettingInPlaceUpdatesWhenDisabledClearsArguments) {
const char* source = "foo";
ASSERT_FALSE(doc.getInPlaceUpdates(&damages, &source));
ASSERT_TRUE(damages.empty());
- ASSERT_EQUALS(static_cast<const char*>(NULL), source);
+ ASSERT_EQUALS(static_cast<const char*>(nullptr), source);
damages.push_back(event);
source = "bar";
size_t size = 1;
ASSERT_FALSE(doc.getInPlaceUpdates(&damages, &source, &size));
ASSERT_TRUE(damages.empty());
- ASSERT_EQUALS(static_cast<const char*>(NULL), source);
+ ASSERT_EQUALS(static_cast<const char*>(nullptr), source);
ASSERT_EQUALS(0U, size);
}
@@ -2929,7 +2929,7 @@ TEST(DocumentInPlace, StringLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueString("bar").transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -2955,7 +2955,7 @@ TEST(DocumentInPlace, BinDataLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueBinary(binData2.length, binData2.type, binData2.data).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -2985,7 +2985,7 @@ TEST(DocumentInPlace, OIDLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueOID(oid2).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3005,7 +3005,7 @@ TEST(DocumentInPlace, BooleanLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueBool(false).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3031,7 +3031,7 @@ TEST(DocumentInPlace, DateLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueDate(mongo::Date_t::fromMillisSinceEpoch(20000)).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3053,7 +3053,7 @@ TEST(DocumentInPlace, NumberIntLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueInt(value2).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3079,7 +3079,7 @@ TEST(DocumentInPlace, TimestampLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueTimestamp(mongo::Timestamp(mongo::Date_t::fromMillisSinceEpoch(20000)))
.transitional_ignore();
@@ -3103,7 +3103,7 @@ TEST(DocumentInPlace, NumberLongLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueLong(value2).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3132,7 +3132,7 @@ TEST(DocumentInPlace, NumberDoubleLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueDouble(value2).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3161,7 +3161,7 @@ TEST(DocumentInPlace, NumberDecimalLifecycle) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueDecimal(value2).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
@@ -3192,7 +3192,7 @@ TEST(DocumentInPlace, DoubleToLongAndBack) {
mmb::Element x = doc.root().leftChild();
mmb::DamageVector damages;
- const char* source = NULL;
+ const char* source = nullptr;
x.setValueLong(value2).transitional_ignore();
ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index a4d2d901e61..0f08d6c56b6 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -135,7 +135,7 @@ void OID::justForked() {
void OID::init() {
// each set* method handles endianness
- setTimestamp(time(0));
+ setTimestamp(time(nullptr));
setInstanceUnique(_instanceUnique);
setIncrement(Increment::next());
}
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index ad890ceb074..d1cd0d53963 100644
--- a/src/mongo/bson/util/builder.h
+++ b/src/mongo/bson/util/builder.h
@@ -458,7 +458,8 @@ public:
verify(z >= 0);
verify(z < maxSize);
_buf.l = prev + z;
- if (strchr(start, '.') == 0 && strchr(start, 'E') == 0 && strchr(start, 'N') == 0) {
+ if (strchr(start, '.') == nullptr && strchr(start, 'E') == nullptr &&
+ strchr(start, 'N') == nullptr) {
write(".0", 2);
}
}
diff --git a/src/mongo/bson/util/builder_test.cpp b/src/mongo/bson/util/builder_test.cpp
index 2dc2662e29d..8ceb8c2c5b8 100644
--- a/src/mongo/bson/util/builder_test.cpp
+++ b/src/mongo/bson/util/builder_test.cpp
@@ -48,7 +48,7 @@ TEST(Builder, StringBuilderAddress) {
const void* longPtr = reinterpret_cast<const void*>(-1);
const void* shortPtr = reinterpret_cast<const void*>(static_cast<uintptr_t>(0xDEADBEEF));
- const void* nullPtr = NULL;
+ const void* nullPtr = nullptr;
StringBuilder sb;
sb << longPtr;