GNOME Bugzilla – Bug 791923
Format string error when compiling with clang
Last modified: 2018-04-23 13:41:09 UTC
Clang is sometimes stricter than GCC on format strings ... [120/557] Compiling C object 'src/plugins/gdb/gdbwire@sta/gdbwire.c.o'. FAILED: src/plugins/gdb/gdbwire@sta/gdbwire.c.o clang -Isrc/plugins/gdb/gdbwire@sta -Isrc/plugins/gdb -I../../source/gnome-builder/src/plugins/gdb -I/home/lantw44/gnome/build/gnome-builder -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wcast-align -Wdeclaration-after-statement -Wformat-nonliteral -Wformat-security -Wmissing-include-dirs -Wnested-externs -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -Wpointer-arith -Wredundant-decls -Wswitch-default -Wswitch-enum -Wuninitialized -Werror=format-security -Werror=format=2 -Werror=empty-body -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=pointer-arith -Werror=init-self -Werror=int-conversion -Werror=missing-include-dirs -Werror=overflow -Werror=return-type -Werror=shadow -Werror=strict-prototypes -Werror=undef -fstack-protector-strong -DHAVE_CONFIG_H -D_GNU_SOURCE -DIDE_COMPILATION -march=corei7 -B/home/lantw44/.local/bin -g3 -O0 -fPIC -Wno-redundant-decls -Wno-switch-default -Wno-missing-declarations -Wno-uninitialized -Wno-declaration-after-statement -MMD -MQ 'src/plugins/gdb/gdbwire@sta/gdbwire.c.o' -MF 'src/plugins/gdb/gdbwire@sta/gdbwire.c.o.d' -o 'src/plugins/gdb/gdbwire@sta/gdbwire.c.o' -c ../../source/gnome-builder/src/plugins/gdb/gdbwire.c ../../source/gnome-builder/src/plugins/gdb/gdbwire.c:611:28: error: format string is not a string literal [-Werror,-Wformat-nonliteral] size = vsnprintf(0, 0, fmt, ap); ^~~ ../../source/gnome-builder/src/plugins/gdb/gdbwire.c:615:37: error: format string is not a string literal [-Werror,-Wformat-nonliteral] size = vsnprintf(buf, size + 1, fmt, ap); ^~~ 2 errors generated. ninja: build stopped: subcommand failed. We have to add __attribute__((__format__(__printf__, 4, 5))) to tell clang how to check the format string.
Created attachment 365936 [details] [review] gdbwire: fix format string error when compiling with clang We cannot use G_GNUC_PRINTF because this file doesn't use GLib.
This file is imported from an amalgamation made with https://github.com/brasko/gdbwire so we probably shouldn't be patching it directly.
Do you mean that we should send this patch to upstream first? I don't know how can I fix the problem without patching gdbwire.c since it happens when compiling gdbwire.c itself.
We need to either patch it upstream, or alter the CFLAGS similar to the vala patch. (We already do that some in src/plugins/gdb/meson.build).
Reported to upstream with patch: https://github.com/brasko/gdbwire/pull/10.
Excellent, thanks for looking into that.
Created attachment 366405 [details] [review] gdbwire: fix format string error when compiling with clang
Created attachment 366406 [details] [review] gdbwire: fix format string error when compiling with clang
Great Attachment 366406 [details] pushed as 53008a2 - gdbwire: fix format string error when compiling with clang
The gdbwire patch is now committed upstream: https://github.com/brasko/gdbwire/commit/d43423e