[CDRIVER-968] Bugs and typos on tutorial examples Created: 28/Oct/15  Updated: 19/Oct/16  Resolved: 30/Oct/15

Status: Closed
Project: C Driver
Component/s: docs
Affects Version/s: 1.2.0
Fix Version/s: 1.3.0

Type: Bug Priority: Minor - P4
Reporter: Iago Rubio Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



 Comments   
Comment by Hannes Magnusson [ 30/Oct/15 ]

Thanks for the review, and the fixes!

We really appreciate the help.

Comment by Githook User [ 30/Oct/15 ]

Author:

{u'username': u'iagorubio', u'name': u'Iago Rubio', u'email': u'iago@iagorubio.com'}

Message: CDRIVER-968: Bugs and typos on tutorial examples
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/db120a3526e44c70672ac1de765485b964c6e58b

Generated at Wed Feb 07 21:11:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.