|
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 }
|
|