diff options
author | Nathan Brown <nathan.brown@10gen.com> | 2019-06-06 10:39:58 -0400 |
---|---|---|
committer | Nathan Brown <nathan.brown@10gen.com> | 2019-06-27 10:04:18 -0400 |
commit | 0fefcf84347a2bcc4961baec0295b9d04047d86f (patch) | |
tree | ce86921e5b14ee83a00400f4f4e8712093505cb8 /src/mongo/bson/bsonelement.cpp | |
parent | a700238800aa2bf1e10c255337ec35373ffd2667 (diff) | |
download | mongo-0fefcf84347a2bcc4961baec0295b9d04047d86f.tar.gz |
SERVER-7143 replace standard library number parsing with custom NumberParser
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index d659f84ee13..4820437c359 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -36,6 +36,7 @@ #include "mongo/base/compare_numbers.h" #include "mongo/base/data_cursor.h" +#include "mongo/base/parse_number.h" #include "mongo/base/simple_string_data_comparator.h" #include "mongo/db/jsobj.h" #include "mongo/platform/strnlen.h" @@ -160,9 +161,12 @@ void BSONElement::jsonStringStream(JsonStringFormat format, s << " "; } - if (strtol(e.fieldName(), nullptr, 10) > count) { + long index; + if (NumberParser::strToAny(10)(e.fieldName(), &index).isOK() && index > count) { s << "undefined"; } else { + // print the element if its index is being printed or if the index it + // belongs to could not be parsed e.jsonStringStream(format, false, pretty ? pretty + 1 : 0, s); e = i.next(); } @@ -514,7 +518,7 @@ std::vector<BSONElement> BSONElement::Array() const { const char* f = e.fieldName(); unsigned u; - Status status = parseNumberFromString(f, &u); + Status status = NumberParser{}(f, &u); if (status.isOK()) { verify(u < 1000000); if (u >= v.size()) |