Skip to content

Commit

Permalink
Use GNU C's "format" function attribute where appropriate
Browse files Browse the repository at this point in the history
Which allows correct type-checking during compilation and avoids errors
when building with clang + -Werror:

[58/71] Compiling C object src/programs/pkexec.p/pkexec.c.o
FAILED: src/programs/pkexec.p/pkexec.c.o
clang -Isrc/programs/pkexec.p -Isrc/programs -I../src/programs -I. -I.. -Isrc/polkitagent -I../src/polkitagent -Isrc -I../src -Isrc/polkit -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c99 -O2 -g -D_GNU_SOURCE -include config.h -Waggregate-return -Wdeclaration-after-statement -Wformat=2 -Wimplicit-function-declaration -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wstrict-prototypes -Wno-format-y2k -Wno-declaration-after-statement -Wno-deprecated-declarations -pthread -DWITH_GZFILEOP -MD -MQ src/programs/pkexec.p/pkexec.c.o -MF src/programs/pkexec.p/pkexec.c.o.d -o src/programs/pkexec.p/pkexec.c.o -c ../src/programs/pkexec.c
../src/programs/pkexec.c:109:25: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
  109 |   s = g_strdup_vprintf (format, var_args);
      |                         ^~~~~~
1 error generated.
[59/71] Compiling C object src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o
FAILED: src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o
clang -Isrc/polkitbackend/libpolkit-backend-1.a.p -Isrc/polkitbackend -I../src/polkitbackend -I. -I.. -Isrc -I../src -Isrc/polkit -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c99 -O2 -g -D_GNU_SOURCE -include config.h -Waggregate-return -Wdeclaration-after-statement -Wformat=2 -Wimplicit-function-declaration -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wstrict-prototypes -Wno-format-y2k -Wno-declaration-after-statement -Wno-deprecated-declarations -fPIC -pthread -DWITH_GZFILEOP -D_POLKIT_COMPILATION -D_POLKIT_BACKEND_COMPILATION '-DPACKAGE_DATA_DIR="/usr/share"' '-DPACKAGE_SYSCONF_DIR="/etc"' -MD -MQ src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o -MF src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o.d -o src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o -c ../src/polkitbackend/polkitbackendauthority.c
../src/polkitbackend/polkitbackendauthority.c:1721:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
 1721 |   message = g_strdup_vprintf (format, var_args);
      |                               ^~~~~~
1 error generated.
  • Loading branch information
mrc0mmand committed Nov 4, 2024
1 parent ffa6882 commit b0e2d47
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/polkitbackend/polkitbackendauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ _color_get (_Color color)

/* ---------------------------------------------------------------------------------------------------- */

G_GNUC_PRINTF(3, 4)
void
polkit_backend_authority_log (PolkitBackendAuthority *authority,
const guint message_log_level,
Expand Down
1 change: 1 addition & 0 deletions src/programs/pkexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ usage (int argc, char *argv[])

/* ---------------------------------------------------------------------------------------------------- */

G_GNUC_PRINTF(3, 4)
static void
log_message (gint level,
gboolean print_to_stderr,
Expand Down

0 comments on commit b0e2d47

Please sign in to comment.