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

Unexpected error using bson_writer and bson_append_binary

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Following code throws an assertion, when i == 1023:

      Writer.c
      #include <stdio.h>
      #include <bson.h>
      #include <assert.h>
      
      int main (int argc, char *argv[])
      {
         bson_writer_t *writer;
         bson_t *doc;
         uint8_t *buf = NULL;
         size_t buflen = 0;
         bool r;
         int i;
         const uint32_t LENGTH = 1 << 20;
         uint8_t *buffer = (uint8_t *) calloc(LENGTH, sizeof(uint8_t));
      
         writer = bson_writer_new (&buf, &buflen, 0, bson_realloc_ctx, NULL);
      
         for (i = 0; i < 10000; i++) {
            r = bson_writer_begin (writer, &doc);
            assert (r);
      
            r = BSON_APPEND_INT32 (doc, "count", i);
      
            r = bson_append_binary(doc, "data", -1, BSON_SUBTYPE_BINARY,
              buffer, LENGTH);
            assert (r);
      
            bson_writer_end (writer);
         }
      
         bson_free (buf);
      
         return 0;
      }
      

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            addar Adda Rathbone
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: