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

Bugs and typos on tutorial examples

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.3.0
    • Affects Version/s: 1.2.0
    • Component/s: Docs
    • None

      As for my conversation with Hannes on the dev group - https://groups.google.com/forum/#!topic/mongodb-dev/GmBettxisD4 - I am going to post here typos and gliches on the Tutorial examples at http://api.mongodb.org/c/1.2.0/tutorial.html .

      Some are bugs that break compilation, and other are quite pedantic warnings that break compilation only if using -Wall -Werror.

      I am going to identify them in my description - as Bug or Warning - so if you want to avoid the warnings you can easily identify them.

      Attached there are a set of files with the original file "fname.c.orig", the proposed fix "fname.c", and a patch "fname.patch" with the differences to easily check them.


      "Bug on 'connect' Example"

      The variable insert is declared as bson_t and then assigned the return value of BCON_NEW that returns a pointer.

      connect.c: In function ‘main’: connect.c:51:11: error: incompatible types when assigning to type ‘bson_t’ from type ‘struct bson_t *’
      insert = BCON_NEW ("hello", BCON_UTF8 ("world"));

      Fixed by declaring the "insert" variable as a pointer.


      "Bug in 'appending bson'
      appending_bson.c: In function ‘main’: appending_bson.c:34:24: 
          error: ‘b’ undeclared (first use in this function) str = bson_as_json (b, NULL); 
      

      The variable "b" at line 34 should be "document".


      'Bug in "Using BCON"'
      In function ‘main’: using_bcon.c:23:4: error: ‘str’ undeclared (first use in this function) 
          str = bson_as_json (doc, NULL); 
      

      The "str" variable should be declared as char *.


      'Warnings on "BCON from json"'
      bson_from_json.c:4:1: error: second argument of ‘main’ should be ‘char **’ [-Werror=main] main (int argc 
      

      The second argument to main is a pointer to char.

      It should be a pointer to a char array.

      In file included from bson_from_json.c:1:0: /usr/include/libbson-1.0/bson.h:191:1: note: 
            expected ‘const uint8_t *’ but argument is of type ‘const char *’ bson_new_from_json (const uint8_t *data, 
      

      There is a non-issue signedness problem on bson_new_from_json.

      Just pointing it here as it breaks on -Werror.


      Non-issue Warning on "insert" and "delete".

      Unused variable cursor.


      'Bugs and warnings on "count"'

      Appart for the signedness warning on bson_new_from_json, there are some missing parameters on that function.

      count_orig.c:21:4: error: too few arguments to function ‘bson_new_from_json’ 
          doc = bson_new_from_json ("{\"hello\" : \"world\"}"); 
      

      The API reference shows the signature:

      bson_t *
      bson_new_from_json (const uint8_t *data, ssize_t len, bson_error_t *error); 
      

      It should be:

      doc = bson_new_from_json ("{\"hello\" : \"world\"}", -1, &error);
      


      'Bug - wrong parameter - on bson_as_json'
      count_orig.c:26:7: error: passing argument 1 of ‘bson_as_json’ from incompatible pointer type [-Werror] 
           str = bson_as_json (&error, NULL); 
      

      The argument in that function should be "doc".


      To check the attached tarball would be easier than to follow this description.

      Hope this helps.

      Note: Looks like I have no permission to make attachments so I temporary uploaded the tarball https://iagorubio.com/~mongo/tutorial.tgz

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            iagorubio Iago Rubio
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: