[CDRIVER-2766] Compiler warnings (gcc-8.1.0) Created: 25/Jul/18  Updated: 28/Oct/23  Resolved: 27/Jul/18

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.12.0
Fix Version/s: 1.13.0

Type: Improvement Priority: Minor - P4
Reporter: Jeroen Ooms [X] Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Seeing the following compiler warnings with GCC 8:

 
bson/bson-iso8601.c: In function '_bson_iso8601_date_parse':
bson/bson-iso8601.c:67:24: warning: 'millis_ptr' may be used uninitialized in this function [-Wmaybe-uninitialized]
 if (!isdigit (str[i])) {
 ~~~^~~
bson/bson-iso8601.c:119:16: note: 'millis_ptr' was declared here
 const char *millis_ptr;
 ^~~~~~~~~~
bson/bson-iso8601.c:67:24: warning: 'sec_ptr' may be used uninitialized in this function [-Wmaybe-uninitialized]
 if (!isdigit (str[i])) {
 ~~~^~~
bson/bson-iso8601.c:118:16: note: 'sec_ptr' was declared here
 const char *sec_ptr;
 ^~~~~~~
 
bson/bson-json.c: In function '_push_callback':
bson/bson-json.c:267:46: warning: array subscript -1 is below array bounds of 'bson_json_stack_frame_t[100]' \{aka 'struct <anonymous>[100]'} [-Warray-bounds]
 (((_delta) + bson->n) == 0 ? bson->bson : &STACK_ELE (_delta, bson))
 ^
bson/bson-json.c:269:26: note: in expansion of macro 'STACK_BSON'
 #define STACK_BSON_CHILD STACK_BSON (0)
 ^~~~~~~~~~
bson/bson-json.c:292:27: note: in expansion of macro 'STACK_BSON_CHILD'
 bson_destroy (STACK_BSON_CHILD); \
 ^~~~~~~~~~~~~~~~
bson/bson-json.c:301:7: note: in expansion of macro 'STACK_PUSH'
 STACK_PUSH (BSON_JSON_FRAME_ARRAY); \
 ^~~~~~~~~~
bson/bson-json.c:1767:7: note: in expansion of macro 'STACK_PUSH_ARRAY'
 STACK_PUSH_ARRAY (_noop ());
 ^~~~~~~~~~~~~~~~

 
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I. -Icommon -Ijsonsl -Ibson -Imongoc -DBSON_COMPILATION -DMONGOC_COMPILATION  -I/usr/local/opt/openssl/include -Wno-deprecated-declarations -DMONGOC_HAVE_SASL_CLIENT_DONE -DBSON_EXTRA_ALIGN  -I/usr/local/include   -fPIC  -Wall -pedantic -c mongoc/mongoc-async-cmd.c -o mongoc/mongoc-async-cmd.o
mongoc/mongoc-async-cmd.c:322:25: warning: arithmetic on a pointer to void is a GNU extension [-Wpointer-arith]
      iovec[0].iov_base += offset;
      ~~~~~~~~~~~~~~~~~ ^ 

 

clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I. -Icommon -Ijsonsl -Ibson -Imongoc -DBSON_COMPILATION -DMONGOC_COMPILATION  -I/usr/local/opt/openssl/include -Wno-deprecated-declarations -DMONGOC_HAVE_SASL_CLIENT_DONE -DBSON_EXTRA_ALIGN  -I/usr/local/include   -fPIC  -Wall -pedantic -c mongoc/mongoc-error.c -o mongoc/mongoc-error.o
mongoc/mongoc-cursor-legacy.c:623:2: warning: no newline at end of file [-Wnewline-eof]



 Comments   
Comment by Kevin Albertson [ 27/Jul/18 ]

Thanks Jeroenooms! I was able to reproduce that warning in GCC 8. Apparently it only appears with optimizations (-O2). Should be fixed now.

Comment by Githook User [ 27/Jul/18 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@10gen.com', 'username': 'kevinAlbs'}

Message: CDRIVER-2766 fix warnings
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/7f73d3fac10183e591d6685ef0f30b0469c0ce77

Comment by Jeroen Ooms [X] [ 25/Jul/18 ]

We use a custom build system. The full gcc command that is below (I think -Wall triggers the warning):

gcc -m64 -I"/usr/include/R" -DNDEBUG -I. -Icommon -Ijsonsl -Ibson -Imongoc -DBSON_COMPILATION -DMONGOC_COMPILATION  -DMONGOC_HAVE_SASL_CLIENT_DONE -DBSON_EXTRA_ALIGN  -I/usr/local/include   -fpic  -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection  -c bson/bson-json.c -o bson/bson-json.o
bson/bson-json.c: In function '_push_callback':
bson/bson-json.c:267:46: warning: array subscript -1 is below array bounds of 'bson_json_stack_frame_t[100]' {aka 'struct <anonymous>[100]'} [-Warray-bounds]
    (((_delta) + bson->n) == 0 ? bson->bson : &STACK_ELE (_delta, bson))
                                              ^
bson/bson-json.c:269:26: note: in expansion of macro 'STACK_BSON'
 #define STACK_BSON_CHILD STACK_BSON (0)
                          ^~~~~~~~~~
bson/bson-json.c:292:27: note: in expansion of macro 'STACK_BSON_CHILD'
             bson_destroy (STACK_BSON_CHILD);         \
                           ^~~~~~~~~~~~~~~~
bson/bson-json.c:301:7: note: in expansion of macro 'STACK_PUSH'
       STACK_PUSH (BSON_JSON_FRAME_ARRAY); \
       ^~~~~~~~~~
bson/bson-json.c:1767:7: note: in expansion of macro 'STACK_PUSH_ARRAY'
       STACK_PUSH_ARRAY (_noop ());
       ^~~~~~~~~~~~~~~~

Comment by Kevin Albertson [ 25/Jul/18 ]

Jeroenooms Are you passing additional C flags through? Can you include the cmake command you're using? If so, can you copy it here? I'm having trouble reproducing those warnings with gcc 8 on Ubuntu 18.04.

Comment by Jeroen Ooms [X] [ 25/Jul/18 ]

Better formatting (I can't edit the post):

This warning appears on Fedora 28 (GCC 8.1.1)

bson/bson-json.c: In function '_push_callback':
bson/bson-json.c:267:46: warning: array subscript -1 is below array bounds of 'bson_json_stack_frame_t[100]' {aka 'struct <anonymous>[100]'} [-Warray-bounds]
    (((_delta) + bson->n) == 0 ? bson->bson : &STACK_ELE (_delta, bson))
                                              ^
bson/bson-json.c:269:26: note: in expansion of macro 'STACK_BSON'
 #define STACK_BSON_CHILD STACK_BSON (0)
                          ^~~~~~~~~~
bson/bson-json.c:292:27: note: in expansion of macro 'STACK_BSON_CHILD'
             bson_destroy (STACK_BSON_CHILD);         \
                           ^~~~~~~~~~~~~~~~
bson/bson-json.c:301:7: note: in expansion of macro 'STACK_PUSH'
       STACK_PUSH (BSON_JSON_FRAME_ARRAY); \
       ^~~~~~~~~~
bson/bson-json.c:1767:7: note: in expansion of macro 'STACK_PUSH_ARRAY'
       STACK_PUSH_ARRAY (_noop ());
       ^~~~~~~~~~~~~~~~

And this on mingw-64 with GCC 8

bson/bson-iso8601.c: In function '_bson_iso8601_date_parse':
bson/bson-iso8601.c:67:24: warning: 'millis_ptr' may be used uninitialized in this function [-Wmaybe-uninitialized]
       if (!isdigit (str[i])) {
                     ~~~^~~
bson/bson-iso8601.c:119:16: note: 'millis_ptr' was declared here
    const char *millis_ptr;
                ^~~~~~~~~~
bson/bson-iso8601.c:67:24: warning: 'sec_ptr' may be used uninitialized in this function [-Wmaybe-uninitialized]
       if (!isdigit (str[i])) {
                     ~~~^~~
bson/bson-iso8601.c:118:16: note: 'sec_ptr' was declared here
    const char *sec_ptr;
                ^~~~~~~

 

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