-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 2.5.0
-
Component/s: Internal Client
-
Fully Compatible
-
Dev Tools 2019-06-17, Dev Tools 2019-07-01, Dev Tools 2019-07-15
See its current implementation:
/** Append a 32 bit unsigned element - cast to a signed int. */ BSONObjBuilder& append(const StringData& fieldName, unsigned n) { return append(fieldName, (int) n); }
As there does not exist a BSON encoding for unsigned integers, this method should not exist. Its existence allows for client code to mistakenly attempt to encode values between INT_MAX and UINT_MAX (to later be read off of the wire by the receiver as negative) with no compiler warnings. To illustrate:
DBClientConnection conn; string errmsg; conn.connect(string("127.0.0.1:27017"), errmsg); unsigned i = UINT_MAX; conn.insert("test.foo", BSON("data" << i)); > db.foo.find() { "_id" : ObjectId("519daf41dc3da869f5a01d17"), "data" : -1 }