diff options
author | Rui Liu <rui.liu@mongodb.com> | 2021-11-30 10:37:15 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-30 11:23:58 +0000 |
commit | ab9802213c7afc0f88d497dee44c83ec6466435c (patch) | |
tree | 6557a31bfe1fcfe3ceb282ab060366632ca49d12 /src/mongo/bson/bsonelement.cpp | |
parent | f84899b472bef1dbb1fd47a069f1dd77503d8c6d (diff) | |
download | mongo-ab9802213c7afc0f88d497dee44c83ec6466435c.tar.gz |
SERVER-61566 Fix and extract coercion to 32-bit int logic in expression parsing
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index d93f928861c..e02dfd07f33 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -515,7 +515,8 @@ StatusWith<long long> BSONElement::parseIntegerElementToNonNegativeLong() const if (number.getValue() < 0) { return Status(ErrorCodes::FailedToParse, - str::stream() << "Expected a positive number in: " << toString(true, true)); + str::stream() + << "Expected a non-negative number in: " << toString(true, true)); } return number; @@ -585,6 +586,21 @@ StatusWith<int> BSONElement::parseIntegerElementToInt() const { return static_cast<int>(valueLong); } +StatusWith<int> BSONElement::parseIntegerElementToNonNegativeInt() const { + auto number = parseIntegerElementToInt(); + if (!number.isOK()) { + return number; + } + + if (number.getValue() < 0) { + return Status(ErrorCodes::FailedToParse, + str::stream() + << "Expected a non-negative number in: " << toString(true, true)); + } + + return number; +} + BSONObj BSONElement::embeddedObjectUserCheck() const { if (MONGO_likely(isABSONObj())) return BSONObj(value(), BSONObj::LargeSizeTrait{}); |