From ac8ba3fa05234c5ac6b8413f4c9c9e7fc7b1f725 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 25 Feb 2010 11:13:05 -0500 Subject: [PATCH] Add __LA_PRINTF to enable format-string checks for GCC. SVN-Revision: 1987 --- libarchive/archive.h | 9 ++++++++- libarchive/archive_string.h | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libarchive/archive.h b/libarchive/archive.h index e31377804..5fcb688d6 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -100,6 +100,13 @@ # define __LA_DECL #endif +#if defined(__GNUC__) && __GNUC__ >= 3 +#define __LA_PRINTF(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ +#endif + #ifdef __cplusplus extern "C" { #endif @@ -789,7 +796,7 @@ __LA_DECL const char *archive_format_name(struct archive *); __LA_DECL int archive_format(struct archive *); __LA_DECL void archive_clear_error(struct archive *); __LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...); + const char *fmt, ...) __LA_PRINTF(3, 4); __LA_DECL void archive_copy_error(struct archive *dest, struct archive *src); __LA_DECL int archive_file_count(struct archive *); diff --git a/libarchive/archive_string.h b/libarchive/archive_string.h index 25d7a8b1e..782c1b162 100644 --- a/libarchive/archive_string.h +++ b/libarchive/archive_string.h @@ -44,6 +44,8 @@ #include #endif +#include "archive.h" + /* * Basic resizable/reusable string support a la Java's "StringBuffer." * @@ -134,10 +136,11 @@ void __archive_string_free(struct archive_string *); /* Like 'vsprintf', but resizes the underlying string as necessary. */ void __archive_string_vsprintf(struct archive_string *, const char *, - va_list); + va_list) __LA_PRINTF(2, 0); #define archive_string_vsprintf __archive_string_vsprintf -void __archive_string_sprintf(struct archive_string *, const char *, ...); +void __archive_string_sprintf(struct archive_string *, const char *, ...) + __LA_PRINTF(2, 3); #define archive_string_sprintf __archive_string_sprintf /* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it. -- 2.47.3