After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 791923 - Format string error when compiling with clang
Format string error when compiling with clang
Status: RESOLVED FIXED
Product: gnome-builder
Classification: Other
Component: general
3.27.x
Other FreeBSD
: Normal normal
: ---
Assigned To: GNOME Builder Maintainers
GNOME Builder Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-12-24 14:34 UTC by Ting-Wei Lan
Modified: 2018-04-23 13:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdbwire: fix format string error when compiling with clang (1.07 KB, patch)
2017-12-24 14:37 UTC, Ting-Wei Lan
none Details | Review
gdbwire: fix format string error when compiling with clang (1.58 KB, patch)
2018-01-06 04:53 UTC, Ting-Wei Lan
none Details | Review
gdbwire: fix format string error when compiling with clang (1.69 KB, patch)
2018-01-06 04:55 UTC, Ting-Wei Lan
committed Details | Review

Description Ting-Wei Lan 2017-12-24 14:34:52 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.
Comment 1 Ting-Wei Lan 2017-12-24 14:37:52 UTC
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.
Comment 2 Christian Hergert 2017-12-25 08:41:27 UTC
This file is imported from an amalgamation made with https://github.com/brasko/gdbwire so we probably shouldn't be patching it directly.
Comment 3 Ting-Wei Lan 2017-12-25 13:42:28 UTC
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.
Comment 4 Christian Hergert 2017-12-26 10:53:05 UTC
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).
Comment 5 Ting-Wei Lan 2017-12-28 08:08:10 UTC
Reported to upstream with patch: https://github.com/brasko/gdbwire/pull/10.
Comment 6 Christian Hergert 2017-12-28 10:07:46 UTC
Excellent, thanks for looking into that.
Comment 7 Ting-Wei Lan 2018-01-06 04:53:57 UTC
Created attachment 366405 [details] [review]
gdbwire: fix format string error when compiling with clang
Comment 8 Ting-Wei Lan 2018-01-06 04:55:11 UTC
Created attachment 366406 [details] [review]
gdbwire: fix format string error when compiling with clang
Comment 9 Christian Hergert 2018-01-06 05:07:08 UTC
Great

Attachment 366406 [details] pushed as 53008a2 - gdbwire: fix format string error when compiling with clang
Comment 10 Ting-Wei Lan 2018-04-23 13:41:09 UTC
The gdbwire patch is now committed upstream:
https://github.com/brasko/gdbwire/commit/d43423e