summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorzoulasc <christos@zoulas.com>2020-01-21 13:34:18 -0500
committerMartin Matuska <martin@matuska.org>2020-01-23 00:19:32 +0100
commit343642bcd20450cacb534d6ea403a1ff6e420806 (patch)
tree1c2a6445898230483befa01f14b7554d82d287e5 /test_utils
parent849740bac9788af44b0e2ae6403ee743b27b628f (diff)
downloadlibarchive-343642bcd20450cacb534d6ea403a1ff6e420806.tar.gz
Add printf attributes to the printflike functions used in tests and fix
the format errors. Closes #1318
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/test_common.h21
-rw-r--r--test_utils/test_main.c22
2 files changed, 28 insertions, 15 deletions
diff --git a/test_utils/test_common.h b/test_utils/test_common.h
index 66047320..80d54f0a 100644
--- a/test_utils/test_common.h
+++ b/test_utils/test_common.h
@@ -115,6 +115,19 @@
#pragma warn -8068 /* Constant out of range in comparison. */
#endif
+
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+ (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
+# ifdef __MINGW_PRINTF_FORMAT
+# define __LA_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+# else
+# define __LA_PRINTF_FORMAT __printf__
+# endif
+# define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__LA_PRINTF_FORMAT, f, a)))
+#else
+# define __LA_PRINTFLIKE(f,a)
+#endif
+
/* Haiku OS and QNX */
#if defined(__HAIKU__) || defined(__QNXNTO__)
/* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */
@@ -266,7 +279,7 @@
skipping_setup(__FILE__, __LINE__);test_skipping
/* Function declarations. These are defined in test_utility.c. */
-void failure(const char *fmt, ...);
+void failure(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
int assertion_assert(const char *, int, int, const char *, void *);
int assertion_chdir(const char *, int, const char *);
int assertion_compare_fflags(const char *, int, const char *, const char *,
@@ -309,10 +322,10 @@ int assertion_utimes(const char *, int, const char *, long, long, long, long );
int assertion_version(const char*, int, const char *, const char *);
void skipping_setup(const char *, int);
-void test_skipping(const char *fmt, ...);
+void test_skipping(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
/* Like sprintf, then system() */
-int systemf(const char * fmt, ...);
+int systemf(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
/* Delay until time() returns a value after this. */
void sleepUntilAfter(time_t);
@@ -375,7 +388,7 @@ void *sunacl_get(int cmd, int *aclcnt, int fd, const char *path);
/* Suck file into string allocated via malloc(). Call free() when done. */
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
-char *slurpfile(size_t *, const char *fmt, ...);
+char *slurpfile(size_t *, const char *fmt, ...) __LA_PRINTFLIKE(2, 3);
/* Dump block of bytes to a file. */
void dumpfile(const char *filename, void *, size_t);
diff --git a/test_utils/test_main.c b/test_utils/test_main.c
index c34c0249..7b8aa70f 100644
--- a/test_utils/test_main.c
+++ b/test_utils/test_main.c
@@ -388,7 +388,7 @@ static const char *refdir;
*/
static int log_console = 0;
static FILE *logfile;
-static void
+static void __LA_PRINTFLIKE(1, 0)
vlogprintf(const char *fmt, va_list ap)
{
#ifdef va_copy
@@ -406,7 +406,7 @@ vlogprintf(const char *fmt, va_list ap)
#endif
}
-static void
+static void __LA_PRINTFLIKE(1, 2)
logprintf(const char *fmt, ...)
{
va_list ap;
@@ -478,7 +478,7 @@ static struct line {
const char *failed_filename;
/* Count this failure, setup up log destination and handle initial report. */
-static void
+static void __LA_PRINTFLIKE(3, 4)
failure_start(const char *filename, int line, const char *fmt, ...)
{
va_list ap;
@@ -751,7 +751,7 @@ static void strdump(const char *e, const char *p, int ewidth, int utf8)
logprintf("]");
logprintf(" (count %d", cnt);
if (n < 0) {
- logprintf(",unknown %d bytes", len);
+ logprintf(",unknown %zu bytes", len);
}
logprintf(")");
@@ -1167,7 +1167,7 @@ assertion_text_file_contents(const char *filename, int line, const char *buff, c
logprintf(" file=\"%s\"\n", fn);
if (n > 0) {
hexdump(contents, buff, n, 0);
- logprintf(" expected\n", fn);
+ logprintf(" expected\n");
hexdump(buff, contents, s, 0);
} else {
logprintf(" File empty, contents should be:\n");
@@ -1497,7 +1497,7 @@ assertion_file_time(const char *file, int line,
}
} else if (filet != t || filet_nsec != nsec) {
failure_start(file, line,
- "File %s has %ctime %lld.%09lld, expected %lld.%09lld",
+ "File %s has %ctime %lld.%09lld, expected %ld.%09ld",
pathname, type, filet, filet_nsec, t, nsec);
failure_finish(NULL);
return (0);
@@ -1593,8 +1593,8 @@ assertion_file_nlinks(const char *file, int line,
r = my_GetFileInformationByName(pathname, &bhfi);
if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks)
return (1);
- failure_start(file, line, "File %s has %d links, expected %d",
- pathname, bhfi.nNumberOfLinks, nlinks);
+ failure_start(file, line, "File %s has %jd links, expected %d",
+ pathname, (intmax_t)bhfi.nNumberOfLinks, nlinks);
failure_finish(NULL);
return (0);
#else
@@ -1605,8 +1605,8 @@ assertion_file_nlinks(const char *file, int line,
r = lstat(pathname, &st);
if (r == 0 && (int)st.st_nlink == nlinks)
return (1);
- failure_start(file, line, "File %s has %d links, expected %d",
- pathname, st.st_nlink, nlinks);
+ failure_start(file, line, "File %s has %jd links, expected %d",
+ pathname, (intmax_t)st.st_nlink, nlinks);
failure_finish(NULL);
return (0);
#endif
@@ -3271,7 +3271,7 @@ assertion_entry_set_acls(const char *file, int line, struct archive_entry *ae,
acls[i].qual, acls[i].name);
if (r != 0) {
ret = 1;
- failure_start(file, line, "type=%#010x, ",
+ failure_start(file, line, "type=%#010x, "
"permset=%#010x, tag=%d, qual=%d name=%s",
acls[i].type, acls[i].permset, acls[i].tag,
acls[i].qual, acls[i].name);