From 4cf4dbfc1e36d0b792b0e4f6eb2359787ff9e155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 27 Apr 2020 16:19:35 +0300 Subject: [PATCH 1/3] meson: Add -Wno-format-zero-length for gcc/clang builds Zero length format strings isn't something that needs to be warned about. --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 34d830c21..b13739792 100644 --- a/meson.build +++ b/meson.build @@ -396,6 +396,8 @@ if cc.get_id() == 'gcc' or cc.get_id() == 'clang' # Due to function casts through (void*) we cannot support -Wpedantic: # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions. '-Wno-pedantic', + # A zero-length format string shouldn't be considered an issue. + '-Wno-format-zero-length', '-Werror=declaration-after-statement', '-Werror=format=2', '-Werror=implicit-function-declaration', From 5ed1e39865dfe4d7e56226fd19449dc199a96c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 5 Apr 2020 00:05:36 +0300 Subject: [PATCH 2/3] gregistrysettings: Fix a mismatched error format string --- gio/gregistrysettingsbackend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gregistrysettingsbackend.c b/gio/gregistrysettingsbackend.c index 0afe54b27..9f9d71857 100644 --- a/gio/gregistrysettingsbackend.c +++ b/gio/gregistrysettingsbackend.c @@ -312,7 +312,7 @@ handle_read_error (LONG result, { /* file not found means key value not set, this isn't an error for us. */ if (result != ERROR_FILE_NOT_FOUND) - g_message_win32_error (result, "Unable to query value %s/%s: %s.\n", + g_message_win32_error (result, "Unable to query value %s/%s", path_name, value_name); } From 6cae01c2f53ce0162043efb69d93678e9c20d733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 5 Apr 2020 00:06:37 +0300 Subject: [PATCH 3/3] Silence clang errors about -Wformat-nonliteral due to missing intermediate attributes By default, meson builds glib with -Werror=format=2, which implies -Werror=format-nonliteral. With these flags, clang errors out on e.g. the g_message_win32_error function, due to "format string is not a string literal". This function takes a format string, and passes the va_list of the arguments onwards to g_strdup_vprintf, which is annotated with printf attributes. When passing a string+va_list to another function, GCC doesn't warn with -Wformat-nonliteral. Clang however does warn, unless the functions themselves (g_message_win32_error and set_error) are decorated with similar printf attributes (to force the same checks upon the caller) - see https://clang.llvm.org/docs/AttributeReference.html#format for reference. Adding these attributes revealed one existing mismatched format string (fixed in the preceding commit). --- gio/gregistrysettingsbackend.c | 2 +- gmodule/gmodule-win32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gio/gregistrysettingsbackend.c b/gio/gregistrysettingsbackend.c index 9f9d71857..b0e295a04 100644 --- a/gio/gregistrysettingsbackend.c +++ b/gio/gregistrysettingsbackend.c @@ -201,7 +201,7 @@ trace (const char *format, * equivalent function for g_warning because none of the registry errors can * result from programmer error (Microsoft programmers don't count), instead * they will mostly occur from people messing with the registry by hand. */ -static void +static void G_GNUC_PRINTF (2, 3) g_message_win32_error (DWORD result_code, const gchar *format, ...) diff --git a/gmodule/gmodule-win32.c b/gmodule/gmodule-win32.c index 5057d256e..fef4d893d 100644 --- a/gmodule/gmodule-win32.c +++ b/gmodule/gmodule-win32.c @@ -39,7 +39,7 @@ #include #endif -static void +static void G_GNUC_PRINTF (1, 2) set_error (const gchar *format, ...) {