[pacman-dev] [PATCH] fix clang -Wformat-nonliteral warnings
Andrew Gregory
andrew.gregory.8 at gmail.com
Sat Feb 9 22:11:49 EST 2013
GCC is smart enough not to issue a warning when calling a printf
function using a va_list; clang is not. Selectively disable the warning
using pragmas to allow building with warnings using clang.
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
Adding a bunch of pragmas doesn't strike me as an ideal solution, but clang's
warning flag documentation is non-existent and I can't find another solution
other than removing -Wformat-nonliteral altogether.
lib/libalpm/util.c | 3 +++
src/pacman/callback.c | 3 +++
src/pacman/util.c | 12 ++++++++++++
src/util/cleanupdelta.c | 3 +++
src/util/testdb.c | 3 +++
src/util/testpkg.c | 4 ++++
6 files changed, 28 insertions(+)
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index f4c33a0..a2f279c 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -463,6 +463,8 @@ int _alpm_logaction(alpm_handle_t *handle, const char *prefix,
prefix = "UNKNOWN";
}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
if(handle->usesyslog) {
/* we can't use a va_list more than once, so we need to copy it
* so we can use the original when calling vfprintf below. */
@@ -486,6 +488,7 @@ int _alpm_logaction(alpm_handle_t *handle, const char *prefix,
ret = vfprintf(handle->logstream, fmt, args);
fflush(handle->logstream);
}
+#pragma clang diagnostic pop
return ret;
}
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index edd5b39..16a04f3 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -772,6 +772,8 @@ void cb_log(alpm_loglevel_t level, const char *fmt, va_list args)
return;
}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
if(on_progress) {
char *string = NULL;
pm_vasprintf(&string, level, fmt, args);
@@ -781,6 +783,7 @@ void cb_log(alpm_loglevel_t level, const char *fmt, va_list args)
} else {
pm_vfprintf(stderr, level, fmt, args);
}
+#pragma clang diagnostic pop
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 03063fb..da3170a 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1460,7 +1460,10 @@ static int question(short preset, char *fmt, va_list args)
fflush(stdout);
fflush(stderr);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
vfprintf(stream, fmt, args);
+#pragma clang diagnostic pop
if(preset) {
fprintf(stream, " %s ", _("[Y/n]"));
@@ -1526,10 +1529,13 @@ int pm_printf(alpm_loglevel_t level, const char *format, ...)
int ret;
va_list args;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
/* print the message using va_arg list */
va_start(args, format);
ret = pm_vfprintf(stderr, level, format, args);
va_end(args);
+#pragma clang diagnostic pop
return ret;
}
@@ -1539,6 +1545,8 @@ int pm_asprintf(char **string, const char *format, ...)
int ret = 0;
va_list args;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
/* print the message using va_arg list */
va_start(args, format);
if(vasprintf(string, format, args) == -1) {
@@ -1546,6 +1554,7 @@ int pm_asprintf(char **string, const char *format, ...)
ret = -1;
}
va_end(args);
+#pragma clang diagnostic pop
return ret;
}
@@ -1561,7 +1570,10 @@ int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_li
}
/* print the message using va_arg list */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
ret = vasprintf(&msg, format, args);
+#pragma clang diagnostic pop
/* print a prefix to the message */
switch(level) {
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 144e038..ff17427 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -39,6 +39,8 @@ static void cleanup(int signum)
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
if(strlen(fmt)) {
switch(level) {
case ALPM_LOG_ERROR: printf("error: "); break;
@@ -48,6 +50,7 @@ static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
}
vprintf(fmt, args);
}
+#pragma clang diagnostic pop
}
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 2017b60..776d73e 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -42,6 +42,8 @@ static void cleanup(int signum)
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
if(strlen(fmt)) {
switch(level) {
case ALPM_LOG_ERROR: printf("error: "); break;
@@ -50,6 +52,7 @@ static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
}
vprintf(fmt, args);
}
+#pragma clang diagnostic pop
}
static int check_localdb_files(void)
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index 96400a7..d310628 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -34,7 +34,11 @@ static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
case ALPM_LOG_WARNING: printf("warning: "); break;
default: return; /* skip other messages */
}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
vprintf(fmt, args);
+#pragma clang diagnostic pop
}
int main(int argc, char *argv[])
--
1.8.1.3
More information about the pacman-dev
mailing list