Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9763

Remove BSONObjBuilder::append(const StringData&, unsigned)

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.3.1
    • 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 }
      

            Assignee:
            alya.berciu@mongodb.com Alya Berciu
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: