[pacman-dev] [PATCH] Add format attributes to all required functions
Allan McRae
allan at archlinux.org
Sun Feb 10 01:51:52 EST 2013
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 <allan at archlinux.org>
---
lib/libalpm/alpm.h | 3 ++-
lib/libalpm/log.c | 4 ++--
lib/libalpm/trans.c | 4 ++--
lib/libalpm/util.h | 5 ++++-
src/pacman/callback.h | 1 +
src/pacman/util.c | 3 ++-
src/pacman/util.h | 6 +++---
src/util/cleanupdelta.c | 1 +
src/util/testdb.c | 1 +
src/util/testpkg.c | 1 +
10 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 729a4c8..14443bb 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -271,8 +271,9 @@ typedef enum _alpm_loglevel_t {
} alpm_loglevel_t;
typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
+
int alpm_logaction(alpm_handle_t *handle, const char *prefix,
- const char *fmt, ...);
+ const char *fmt, ...) __attribute__((format(printf, 3, 4)));
/**
* Events.
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index a8639b4..271bd00 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -39,8 +39,8 @@
* @param fmt output format
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix, const
- char *fmt, ...)
+int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix,
+ const char *fmt, ...)
{
int ret;
va_list args;
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index b0488eb..8d4e0e7 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -218,8 +218,8 @@ int SYMEXPORT alpm_trans_release(alpm_handle_t *handle)
if(_alpm_handle_unlock(handle)) {
_alpm_log(handle, ALPM_LOG_WARNING, _("could not remove lock file %s\n"),
handle->lockfile);
- alpm_logaction(handle, "warning: could not remove lock file %s\n",
- handle->lockfile);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: could not remove lock file %s\n", handle->lockfile);
}
}
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 93b6573..56031f3 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -120,7 +120,10 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
alpm_list_t *list, int breakfirst);
ssize_t _alpm_files_in_directory(alpm_handle_t *handle, const char *path, int full_count);
-int _alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, va_list args);
+
+int _alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, va_list args)
+ __attribute__((format(printf, 3, 0)));
+
int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]);
int _alpm_ldconfig(alpm_handle_t *handle);
int _alpm_str_cmp(const void *s1, const void *s2);
diff --git a/src/pacman/callback.h b/src/pacman/callback.h
index 4717360..a291fc7 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 03063fb..6afd701 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -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 c38291a..2d1e698 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 144e038..4f34435 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 2017b60..7b08cb0 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 96400a7..10b2f2c 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') {
--
1.8.1.3
More information about the pacman-dev
mailing list