Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3626

Creating bson from json: Losing decimal digits in QT application

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.17.0-beta
    • Component/s: libbson
    • None
    • Environment:
      Ubuntu 16.04 with Qt

      When creating a bson from a json string, decimal digits get lost when running in a QT environment in release mode.

      Input string is

      "{\"d\": 1.987}"
      

      Output string (converted back to Json for readability) when running in debug mode with gdb enabled is

      "{ "d" : { "$numberDouble" : "1.9870000000000000995" } }"
      

      , which is fine, but when running in release mode it is

      "{ "d" : { "$numberDouble" : "1.0" } }".
      

      Tested with Qt 5.9.4 and current version 5.14.2.

      This is the minimal example:

      #include <QCoreApplication>
      #include <bson.h>
      #include <iostream>
      
      #define BSON_JSON_DEFAULT_BUF_SIZE (1 << 14)
      
      int main(int argc, char *argv[]) {
      QCoreApplication a(argc, argv);
      
      std::string json = "{\"d\": 1.987}";
      bson_t * bson;
      bson_error_t err;
      const uint8_t* data = (const uint8_t *)(json.c_str());
      int len = -1;
      
      ///1
      //bson = bson_new_from_json(data, len, &err);
      
      ///inside bson_new_from_json:
      if (len < 0) {
      len = (ssize_t) strlen ((const char *) data);
      }
      bson_json_reader_t *reader;
      bson = bson_new ();
      reader = bson_json_data_reader_new (false, BSON_JSON_DEFAULT_BUF_SIZE);
      bson_json_data_reader_ingest (reader, data, len);
      int r = bson_json_reader_read (reader, bson, &err);
      
      ///test:
      char* jsonD;
      if ((jsonD = bson_as_canonical_extended_json (bson, NULL))) {
      std::cout << "json from bson: " << jsonD << std::endl;
      }
      
      return a.exec();
      }
      

       
      When removing QCoreApplication and a.exec() everything works fine, so this is connected to Qt, but I cannot find out what is exactly going on in bson_json_reader_read(). I guess that Qt may define something in debug mode, which affects the bson library.

            Assignee:
            roberto.sanchez@mongodb.com Roberto Sanchez
            Reporter:
            christoph.moench@htwk-leipzig.de Christoph Mönch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: