Opened 9 years ago

Closed 9 years ago

#6008 closed defect (fixed)

Better C++11/C11 compatibility

Reported by: Even Rouault Owned by: warmerdam
Priority: normal Milestone: 2.0.1
Component: ConfigBuild Version: unspecified
Severity: normal Keywords:
Cc:

Description

When compiling with -std=c11, the following warnings are emitted, which cause random crash in misc_6 test (on 64bit since the returned char* pointer of strdup() is cast as a int) :

json_object.c: In function ‘gdal_json_object_object_add’:
json_object.c:382:3: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
   lh_table_insert(jso->o.c_object, strdup(key), val);
   ^
json_object.c:382:3: warning: passing argument 2 of ‘gdal_lh_table_insert’ makes pointer from integer without a cast [enabled by default]
In file included from config.h:20:0,
                 from json_object.c:15:
symbol_renames.h:112:25: note: expected ‘void *’ but argument is of type ‘int’
 #define lh_table_insert gdal_lh_table_insert
                         ^
linkhash.h:231:12: note: in expansion of macro ‘lh_table_insert’
 extern int lh_table_insert(struct lh_table *t, void *k, const void *v);
            ^
json_object.c: In function ‘gdal_json_object_new_string’:
json_object.c:636:23: warning: assignment makes pointer from integer without a cast [enabled by default]
   jso->o.c_string.str = strdup(s);
                       ^
gcc -std=c11 -fPIC  -g -DDEBUG  -Wall -Wdeclaration-after-statement -Wunused-parameter  -DOGR_ENABLED -I/home/even/gdal_trunk/gdal/port -I/usr/include/qhull -I/home/even/install-openjpeg-dev/include -I/usr/include -I/home/even/mapbox/prefix -I/home/even/mapbox/prefix/include -I/home/even/mapbox/prefix -I/home/even/mapbox/prefix/include  -DGDAL_COMPILATION -c -o ../../o/json_tokener.o json_tokener.c
json_tokener.c: In function ‘gdal_json_tokener_parse_ex’:
json_tokener.c:676:6: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
      obj_field_name = strdup(tok->pb->buf);
      ^
json_tokener.c:676:21: warning: assignment makes pointer from integer without a cast [enabled by default]
      obj_field_name = strdup(tok->pb->buf);
                     ^

This is due to strdup() not being in the C standard, but as an extension that must for example be enabled with -D_XOPEN_SOURCE=500

Change History (1)

comment:1 by Even Rouault, 9 years ago

Component: defaultConfigBuild
Milestone: 2.0.1
Resolution: fixed
Status: newclosed

trunk r29407, branches/2.0 r29408 "Internal libjson: fix for C11 compatibility (fix runtime crash, #6008)"

Note: See TracTickets for help on using tickets.