From 3fa2830829de2e3aa4bb916f164ae2fd75542ef3 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sun, 10 Feb 2013 16:47:39 +1000 Subject: Add format attributes to all required functions Fixes all clang warnings with -Wformat-literal. Also, fix genuine formating issue discovered once adding these attributes and add a cast to prevent a gcc warning. Signed-off-by: Allan McRae --- src/pacman/callback.h | 1 + src/pacman/util.c | 5 +++-- src/pacman/util.h | 6 +++--- src/util/cleanupdelta.c | 1 + src/util/testdb.c | 1 + src/util/testpkg.c | 1 + 6 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/pacman/callback.h b/src/pacman/callback.h index 4717360f..a291fc74 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -41,6 +41,7 @@ void cb_dl_total(off_t total); void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total); /* callback to handle messages/notifications from pacman library */ +__attribute__((format(printf, 2, 0))) void cb_log(alpm_loglevel_t level, const char *fmt, va_list args); #endif /* _PM_CALLBACK_H */ diff --git a/src/pacman/util.c b/src/pacman/util.c index 03063fb5..3270c746 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -871,7 +871,7 @@ static void _display_targets(alpm_list_t *targets, int verbose) } /* print to screen */ - pm_asprintf(&str, _("Packages (%d):"), alpm_list_count(targets)); + pm_asprintf(&str, _("Packages (%zd):"), alpm_list_count(targets)); printf("\n"); cols = getcols(fileno(stdout)); @@ -992,7 +992,7 @@ static char *pkg_get_location(alpm_pkg_t *pkg) case PM_OP_SYNC: servers = alpm_db_get_servers(alpm_pkg_get_db(pkg)); if(servers) { - pm_asprintf(&string, "%s/%s", servers->data, + pm_asprintf(&string, "%s/%s", (char *)(servers->data), alpm_pkg_get_filename(pkg)); return string; } @@ -1443,6 +1443,7 @@ int select_question(int count) /* presents a prompt and gets a Y/N answer */ +__attribute__((format(printf, 2, 0))) static int question(short preset, char *fmt, va_list args) { char response[32]; diff --git a/src/pacman/util.h b/src/pacman/util.h index c38291a9..2d1e6989 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -72,11 +72,11 @@ void print_packages(const alpm_list_t *packages); void select_display(const alpm_list_t *pkglist); int select_question(int count); int multiselect_question(char *array, int count); -int yesno(char *fmt, ...); -int noyes(char *fmt, ...); +int yesno(char *fmt, ...) __attribute__((format(printf, 1, 2))); +int noyes(char *fmt, ...) __attribute__((format(printf, 1, 2))); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); -int pm_asprintf(char **string, const char *format, ...); +int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3))); int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 144e0388..4f344350 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -37,6 +37,7 @@ static void cleanup(int signum) exit(signum); } +__attribute__((format(printf, 2, 0))) static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) { if(strlen(fmt)) { diff --git a/src/util/testdb.c b/src/util/testdb.c index 2017b60f..7b08cb0d 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -40,6 +40,7 @@ static void cleanup(int signum) exit(signum); } +__attribute__((format(printf, 2, 0))) static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) { if(strlen(fmt)) { diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 96400a75..10b2f2c2 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -24,6 +24,7 @@ #define BASENAME "testpkg" +__attribute__((format(printf, 2, 0))) static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) { if(fmt[0] == '\0') { -- cgit v1.2.3-24-g4f1b