summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/bson/bsonelement.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h
index 84d8f7fb909..3502ff8a7f6 100644
--- a/src/mongo/bson/bsonelement.h
+++ b/src/mongo/bson/bsonelement.h
@@ -1056,7 +1056,12 @@ Status BSONElement::tryCoerce(T* out) const {
if (!std::isfinite(d)) {
return {ErrorCodes::BadValue, "Unable to coerce NaN/Inf to integral type"};
}
- if ((d > std::numeric_limits<T>::max()) || (d < std::numeric_limits<T>::lowest())) {
+ // TODO(SERVER-48076): Revisit the use of the > operator for the T::max() comparison in
+ // the case when T is a 64 bit type. When T is a 64 bit type, this comparison should
+ // be >=, as the conversion rounds the the max to 2**63 which is double that cannot be
+ // converted.
+ if ((d > static_cast<double>(std::numeric_limits<T>::max())) ||
+ (d < std::numeric_limits<T>::lowest())) {
return {ErrorCodes::BadValue, "Out of bounds coercing to integral value"};
}
val = static_cast<long long>(d);