New GCC plugin in 3rd party project (FRRouting): extended printf warnings

David Lamparter equinox@diac24.net
Fri Jul 17 11:37:20 GMT 2020


P.S.: here's the output you get from the included format-test.c:

$ gcc -Wall -Wextra -Wno-unused -fplugin=./frr-format.so -fno-diagnostics-show-caret -c -o format-test.o format-test.c
format-test.c: In function ‘test’:
format-test.c:38:12: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 2 has type ‘long int’ (strict match required [B]) [-Wformat=]
format-test.c:39:12: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 2 has type ‘int’ [-Wformat=]
format-test.c:41:12: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 2 has type ‘mytype’ {aka ‘long unsigned int’} (strict match required [B]) [-Wformat=]
format-test.c:43:12: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} (strict match required [B]) [-Wformat=]
format-test.c:44:12: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 2 has type ‘pid_t’ {aka ‘int’} [-Wformat=]
format-test.c:47:12: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘int’ [-Wformat=]
format-test.c:48:12: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} (strict match required [C]) [-Wformat=]
format-test.c:50:12: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} (strict match required [C]) [-Wformat=]
format-test.c:51:12: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘pid_t’ {aka ‘int’} [-Wformat=]
format-test.c:54:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘int’ [-Wformat=]
format-test.c:55:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} (strict match required [Z]) [-Wformat=]
format-test.c:55:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} (strict match required [C]) [-Wformat=]
format-test.c:57:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} (strict match required [Z]) [-Wformat=]
format-test.c:57:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} (strict match required [C]) [-Wformat=]
format-test.c:58:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘pid_t’ {aka ‘int’} [-Wformat=]
format-test.c:61:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
format-test.c:62:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
format-test.c:63:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
format-test.c:64:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
format-test.c:65:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘pid_t’ {aka ‘int’} (strict match required [C]) [-Wformat=]
format-test.c:67:12: warning: format ‘%Lu’ expects argument of type ‘uint64_t’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} (strict match required [B]) [-Wformat=]
format-test.c:68:12: warning: format ‘%Lu’ expects argument of type ‘uint64_t’, but argument 2 has type ‘long int’ (strict match required [B]) [-Wformat=]
format-test.c:69:12: warning: format ‘%Lu’ expects argument of type ‘uint64_t’, but argument 2 has type ‘int’ [-Wformat=]
format-test.c:71:12: warning: format ‘%Lu’ expects argument of type ‘uint64_t’, but argument 2 has type ‘mytype’ {aka ‘long unsigned int’} (strict match required [B]) [-Wformat=]
format-test.c:72:12: warning: format ‘%Lu’ expects argument of type ‘uint64_t’, but argument 2 has type ‘mysize’ {aka ‘long unsigned int’} (strict match required [B]) [-Wformat=]
format-test.c:73:12: warning: format ‘%Lu’ expects argument of type ‘uint64_t’, but argument 2 has type ‘pid_t’ {aka ‘int’} [-Wformat=]
format-test.c:76:12: warning: format ‘%Ld’ expects argument of type ‘int64_t’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} (strict match required [X]) [-Wformat=]
format-test.c:77:12: warning: format ‘%Ld’ expects argument of type ‘int64_t’, but argument 2 has type ‘long int’ (strict match required [B]) [-Wformat=]
format-test.c:78:12: warning: format ‘%Ld’ expects argument of type ‘int64_t’, but argument 2 has type ‘int’ [-Wformat=]
format-test.c:80:12: warning: format ‘%Ld’ expects argument of type ‘int64_t’, but argument 2 has type ‘mytype’ {aka ‘long unsigned int’} (strict match required [B]) [-Wformat=]
format-test.c:81:12: warning: format ‘%Ld’ expects argument of type ‘int64_t’, but argument 2 has type ‘mysize’ {aka ‘long unsigned int’} (strict match required [X]) [-Wformat=]
format-test.c:82:12: warning: format ‘%Ld’ expects argument of type ‘int64_t’, but argument 2 has type ‘pid_t’ {aka ‘int’} [-Wformat=]
format-test.c:87:12: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} (strict match required [C]) [-Wformat=]
format-test.c:89:12: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} (strict match required [C]) [-Wformat=]
format-test.c:91:13: warning: format ‘%pI4’ expects argument of type ‘in_addr_t {aka unsigned int} *’, but argument 2 has type ‘long int *’ [-Wformat=]
format-test.c:100:13: warning: format ‘%pI4’ expects argument of type ‘in_addr_t {aka unsigned int} *’, but argument 2 has type ‘not_in_addr_t *’ {aka ‘unsigned int *’} [-Wformat=]
format-test.c:101:13: warning: format ‘%pI4’ expects argument of type ‘in_addr_t {aka unsigned int} *’, but argument 2 has type ‘void *’ [-Wformat=]
format-test.c:110:13: warning: format ‘%pI4’ expects argument of type ‘in_addr_t {aka unsigned int} *’, but argument 2 has type ‘struct other *’ [-Wformat=]


-David


More information about the Gcc mailing list