#10 Dangerous printf/sprintf format/type warnings

v1.0 (example)
closed-fixed
CSB
None
6
2014-03-21
2011-11-23
No

I get these same warnings even if I use the -m32 gcc option.

/Developer/usr/bin/gcc -DHAVE_CONFIG_H -I. -I.. -I../include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -L/Developer/SDKs/MacOSX10.7.sdk/usr/lib -MT diag_l0_me.o -MD -MP -MF .deps/diag_l0_me.Tpo -c -o diag_l0_me.o diag_l0_me.c
diag_l0_me.c: In function ‘diag_l0_muleng_recv’:
diag_l0_me.c:741: warning: format ‘%x’ expects type ‘unsigned int’, but argument 3 has type ‘ssize_t’

/Developer/usr/bin/gcc -DHAVE_CONFIG_H -I. -I.. -I../include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -L/Developer/SDKs/MacOSX10.7.sdk/usr/lib -MT diag_l0_elm.o -MD -MP -MF .deps/diag_l0_elm.Tpo -c -o diag_l0_elm.o diag_l0_elm.c
diag_l0_elm.c: In function ‘diag_l0_elm_sendcmd’:
diag_l0_elm.c:134: warning: field precision should have type ‘int’, but argument 5 has type ‘size_t’
diag_l0_elm.c:134: warning: format ‘%.*s’ expects type ‘char *’, but argument 6 has type ‘const void *’
diag_l0_elm.c:139: warning: field precision should have type ‘int’, but argument 5 has type ‘size_t’
diag_l0_elm.c:139: warning: format ‘%.*s’ expects type ‘char *’, but argument 6 has type ‘const void *’
diag_l0_elm.c:177: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘char **’
diag_l0_elm.c:199: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘char **’
diag_l0_elm.c: In function ‘diag_l0_elm_open’:
diag_l0_elm.c:272: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘char **’
diag_l0_elm.c:288: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘char **’
diag_l0_elm.c: In function ‘diag_l0_elm_send’:
diag_l0_elm.c:412: warning: format ‘%d’ expects type ‘int’, but argument 5 has type ‘size_t’
diag_l0_elm.c:427: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘char (*)[25]’
diag_l0_elm.c: In function ‘diag_l0_elm_recv’:
diag_l0_elm.c:508: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 3 has type ‘char *’

/Developer/usr/bin/gcc -DHAVE_CONFIG_H -I. -I.. -I../include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -L/Developer/SDKs/MacOSX10.7.sdk/usr/lib -MT diag_l0_sim.o -MD -MP -MF .deps/diag_l0_sim.Tpo -c -o diag_l0_sim.o diag_l0_sim.c
diag_l0_sim.c: In function ‘sim_find_responses’:
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 3 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 4 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 5 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 6 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 7 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 8 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 9 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 10 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 11 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 12 has type ‘unsigned char *’
diag_l0_sim.c:267: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 13 has type ‘unsigned char *’
diag_l0_sim.c: In function ‘sim_parse_response’:
diag_l0_sim.c:373: warning: format ‘%x’ expects type ‘unsigned int *’, but argument 3 has type ‘unsigned char *’
diag_l0_sim.c: In function ‘sim_read_cfg’:
diag_l0_sim.c:422: warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘char *’
diag_l0_sim.c:427: warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘char *’

/Developer/usr/bin/gcc -DHAVE_CONFIG_H -I. -I.. -I../include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -isysroot /Developer/SDKs/MacOSX10.7.sdk -I/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -L/Developer/SDKs/MacOSX10.7.sdk/usr/lib -MT diag_tty.o -MD -MP -MF .deps/diag_tty.Tpo -c -o diag_tty.o diag_tty.c
diag_tty.c: In function ‘diag_tty_control’:
diag_tty.c:499: warning: format ‘%03ld’ expects type ‘long int’, but argument 6 has type ‘__darwin_suseconds_t’

Discussion

  • CSB

    CSB - 2014-02-27
    • assigned_to: CSB
    • Group: --> v1.0 (example)
    • Priority: 5 --> 6
     
  • CSB

    CSB - 2014-02-27

    I finally have some time to work on freediag again. Thanks for your reports. In case you're still watching this bug:

    I added correct casts and fixes for most of what you submitted (not on CVS yet), except the last one :
    "diag_tty.c:499 warning: format ‘%03ld’ expects type ‘long int’, but argument 6 has type ‘__darwin_suseconds_t’ "
    I'm not familiar with darwin, do you think it would suffice to just cast to (long int) systematically for all platforms ?

     
  • CSB

    CSB - 2014-03-21

    All of this is fixed in CVS except the Darwin-specific issue. Waiting for further information before reopening.

     
  • CSB

    CSB - 2014-03-21
    • status: open --> closed-fixed
     

Log in to post a comment.