diff options
author | zoulasc <christos@zoulas.com> | 2020-01-21 13:34:18 -0500 |
---|---|---|
committer | Martin Matuska <martin@matuska.org> | 2020-01-23 00:19:32 +0100 |
commit | 343642bcd20450cacb534d6ea403a1ff6e420806 (patch) | |
tree | 1c2a6445898230483befa01f14b7554d82d287e5 | |
parent | 849740bac9788af44b0e2ae6403ee743b27b628f (diff) | |
download | libarchive-343642bcd20450cacb534d6ea403a1ff6e420806.tar.gz |
Add printf attributes to the printflike functions used in tests and fix
the format errors.
Closes #1318
38 files changed, 106 insertions, 79 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 552aef96..9e46c6ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,10 @@ IF("${CMAKE_C_PLATFORM_ID}" MATCHES "^(HP-UX)$") ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t ENDIF() +IF(MINGW) + ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO) +ENDIF() + # INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceRuns) diff --git a/cat/test/test_0.c b/cat/test/test_0.c index f9fe5d84..c806c243 100644 --- a/cat/test/test_0.c +++ b/cat/test/test_0.c @@ -59,7 +59,7 @@ DEFINE_TEST(test_0) * we know some option that will succeed. */ if (0 != systemf("%s --version >" DEV_NULL, testprog)) { - failure("Unable to successfully run: %s --version\n", testprog, testprog); + failure("Unable to successfully run: %s --version\n", testprog); assert(0); } diff --git a/cpio/test/test_basic.c b/cpio/test/test_basic.c index a8fedf89..b7162534 100644 --- a/cpio/test/test_basic.c +++ b/cpio/test/test_basic.c @@ -33,15 +33,15 @@ verify_files(const char *msg) */ /* Regular file with 2 links. */ - failure(msg); + failure("%s", msg); assertIsReg("file", 0644); - failure(msg); + failure("%s", msg); assertFileSize("file", 10); - failure(msg); + failure("%s", msg); assertFileNLinks("file", 2); /* Another name for the same file. */ - failure(msg); + failure("%s", msg); assertIsHardlink("linkfile", "file"); /* Symlink */ @@ -49,11 +49,11 @@ verify_files(const char *msg) assertIsSymlink("symlink", "file", 0); /* Another file with 1 link and different permissions. */ - failure(msg); + failure("%s", msg); assertIsReg("file2", 0777); - failure(msg); + failure("%s", msg); assertFileSize("file2", 10); - failure(msg); + failure("%s", msg); assertFileNLinks("file2", 1); /* dir */ diff --git a/cpio/test/test_format_newc.c b/cpio/test/test_format_newc.c index 6c981f6a..49387a73 100644 --- a/cpio/test/test_format_newc.c +++ b/cpio/test/test_format_newc.c @@ -205,9 +205,11 @@ DEFINE_TEST(test_format_newc) gid = from_hex(e + 30, 8); /* gid */ assertEqualMem(e + 38, "00000003", 8); /* nlink */ t = from_hex(e + 46, 8); /* mtime */ - failure("t=0x%08x now=0x%08x=%d", t, now, now); + failure("t=%#08jx now=%#08jx=%jd", (intmax_t)t, (intmax_t)now, + (intmax_t)now); assert(t <= now); /* File wasn't created in future. */ - failure("t=0x%08x now - 2=0x%08x = %d", t, now - 2, now - 2); + failure("t=%#08jx now - 2=%#08jx=%jd", (intmax_t)t, (intmax_t)now - 2, + (intmax_t)now - 2); assert(t >= now - 2); /* File was created w/in last 2 secs. */ failure("newc format stores body only with last appearance of a link\n" " first appearance should be empty, so this file size\n" @@ -243,7 +245,8 @@ DEFINE_TEST(test_format_newc) assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ assertEqualMem(e + 38, "00000001", 8); /* nlink */ t2 = from_hex(e + 46, 8); /* mtime */ - failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + failure("First entry created at t=%#08jx this entry created" + " at t2=%#08jx", (intmax_t)t, (intmax_t)t2); assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualMem(e + 54, "00000005", 8); /* File size */ fs = from_hex(e + 54, 8); @@ -278,7 +281,8 @@ DEFINE_TEST(test_format_newc) assertEqualInt(nlinks("dir"), from_hex(e + 38, 8)); /* nlinks */ #endif t2 = from_hex(e + 46, 8); /* mtime */ - failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + failure("First entry created at t=%#08jx this entry created at" + "t2=%#08jx", (intmax_t)t, (intmax_t)t2); assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualMem(e + 54, "00000000", 8); /* File size */ fs = from_hex(e + 54, 8); @@ -311,7 +315,8 @@ DEFINE_TEST(test_format_newc) assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ assertEqualMem(e + 38, "00000003", 8); /* nlink */ t2 = from_hex(e + 46, 8); /* mtime */ - failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + failure("First entry created at t=%#08jx this entry created at" + "t2=%#08jx", (intmax_t)t, (intmax_t)t2); assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ assertEqualInt(10, from_hex(e + 54, 8)); /* File size */ fs = from_hex(e + 54, 8); diff --git a/libarchive/test/test_compat_zip.c b/libarchive/test/test_compat_zip.c index 39152206..813ea5dc 100644 --- a/libarchive/test/test_compat_zip.c +++ b/libarchive/test/test_compat_zip.c @@ -156,7 +156,7 @@ DEFINE_TEST(test_compat_zip_4) size_t s; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* SFX files require seek support. */ assert((a = archive_read_new()) != NULL); @@ -214,7 +214,7 @@ DEFINE_TEST(test_compat_zip_5) size_t s; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* Verify with seek support. * Everything works correctly here. */ @@ -370,7 +370,7 @@ DEFINE_TEST(test_compat_zip_6) size_t s; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); @@ -402,7 +402,7 @@ DEFINE_TEST(test_compat_zip_7) int i; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); for (i = 1; i < 1000; ++i) { assert((a = archive_read_new()) != NULL); @@ -436,7 +436,7 @@ DEFINE_TEST(test_compat_zip_8) size_t s; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); diff --git a/libarchive/test/test_fuzz.c b/libarchive/test/test_fuzz.c index d02fd993..b2654c4a 100644 --- a/libarchive/test/test_fuzz.c +++ b/libarchive/test/test_fuzz.c @@ -119,7 +119,8 @@ test_fuzz(const struct files *filesets) for (i = 0; filesets[n].names[i] != NULL; ++i) { char *newraw; - tmp = slurpfile(&size, filesets[n].names[i]); + tmp = slurpfile(&size, "%s", + filesets[n].names[i]); newraw = realloc(rawimage, oldsize + size); if (!assert(newraw != NULL)) { diff --git a/libarchive/test/test_read_extract.c b/libarchive/test/test_read_extract.c index cd06096e..2b1a21e4 100644 --- a/libarchive/test/test_read_extract.c +++ b/libarchive/test/test_read_extract.c @@ -120,7 +120,7 @@ DEFINE_TEST(test_read_extract) assertA(0 == archive_read_support_filter_all(a)); assertA(0 == archive_read_open_memory(a, buff, BUFF_SIZE)); /* Restore first entry with _EXTRACT_PERM. */ - failure("Error reading first entry", i); + failure("Error reading first entry"); assertA(0 == archive_read_next_header(a, &ae)); assertA(0 == archive_read_extract(a, ae, ARCHIVE_EXTRACT_PERM)); /* Rest of entries get restored with no flags. */ diff --git a/libarchive/test/test_read_format_gtar_sparse.c b/libarchive/test/test_read_format_gtar_sparse.c index 7ab13c11..6d15a474 100644 --- a/libarchive/test/test_read_format_gtar_sparse.c +++ b/libarchive/test/test_read_format_gtar_sparse.c @@ -214,8 +214,9 @@ verify_archive_file(const char *name, struct archive_contents *ac) * Any byte before the expected * data must be NULL. */ - failure("%s: pad at offset %d " - "should be zero", name, actual.o); + failure("%s: pad at offset %jd " + "should be zero", name, + (intmax_t)actual.o); assertEqualInt(c, 0); } else if (actual.o == expect.o) { /* diff --git a/libarchive/test/test_read_format_zip.c b/libarchive/test/test_read_format_zip.c index 9afbfb6c..04f7e98c 100644 --- a/libarchive/test/test_read_format_zip.c +++ b/libarchive/test/test_read_format_zip.c @@ -194,7 +194,7 @@ test_basic(void) verify_basic(a, 1); /* Verify with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); @@ -264,7 +264,7 @@ test_info_zip_ux(void) verify_info_zip_ux(a, 1); /* Verify with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); @@ -328,7 +328,7 @@ test_extract_length_at_end(void) verify_extract_length_at_end(a, 1); /* Verify extraction with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); @@ -347,7 +347,7 @@ test_symlink(void) struct archive_entry *ae; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* Symlinks can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); diff --git a/libarchive/test/test_read_format_zip_7075_utf8_paths.c b/libarchive/test/test_read_format_zip_7075_utf8_paths.c index 7b78770a..a0a510c8 100644 --- a/libarchive/test/test_read_format_zip_7075_utf8_paths.c +++ b/libarchive/test/test_read_format_zip_7075_utf8_paths.c @@ -90,7 +90,7 @@ DEFINE_TEST(test_read_format_zip_utf8_paths) assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); /* Verify with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); diff --git a/libarchive/test/test_read_format_zip_comment_stored.c b/libarchive/test/test_read_format_zip_comment_stored.c index b92b2886..95df0107 100644 --- a/libarchive/test/test_read_format_zip_comment_stored.c +++ b/libarchive/test/test_read_format_zip_comment_stored.c @@ -38,7 +38,7 @@ verify(const char *refname) struct archive_entry *ae; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* Symlinks can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); diff --git a/libarchive/test/test_read_format_zip_extra_padding.c b/libarchive/test/test_read_format_zip_extra_padding.c index 54f7fa04..6e2f836f 100644 --- a/libarchive/test/test_read_format_zip_extra_padding.c +++ b/libarchive/test/test_read_format_zip_extra_padding.c @@ -80,7 +80,7 @@ DEFINE_TEST(test_read_format_zip_extra_padding) assertEqualInt(ARCHIVE_OK, archive_read_free(a)); /* Verify with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); diff --git a/libarchive/test/test_read_format_zip_high_compression.c b/libarchive/test/test_read_format_zip_high_compression.c index 42faed37..16cfbb18 100644 --- a/libarchive/test/test_read_format_zip_high_compression.c +++ b/libarchive/test/test_read_format_zip_high_compression.c @@ -56,7 +56,7 @@ DEFINE_TEST(test_read_format_zip_high_compression) } extract_reference_file(refname); - p = slurpfile(&archive_size, refname); + p = slurpfile(&archive_size, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); diff --git a/libarchive/test/test_read_format_zip_jar.c b/libarchive/test/test_read_format_zip_jar.c index ffb520eb..912e6713 100644 --- a/libarchive/test/test_read_format_zip_jar.c +++ b/libarchive/test/test_read_format_zip_jar.c @@ -40,7 +40,7 @@ DEFINE_TEST(test_read_format_zip_jar) char data[16]; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a)); diff --git a/libarchive/test/test_read_format_zip_mac_metadata.c b/libarchive/test/test_read_format_zip_mac_metadata.c index 99b70123..3f2813cc 100644 --- a/libarchive/test/test_read_format_zip_mac_metadata.c +++ b/libarchive/test/test_read_format_zip_mac_metadata.c @@ -76,7 +76,7 @@ DEFINE_TEST(test_read_format_zip_mac_metadata) }; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* Mac metadata can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); diff --git a/libarchive/test/test_read_format_zip_malformed.c b/libarchive/test/test_read_format_zip_malformed.c index e14a3f56..f1160648 100644 --- a/libarchive/test/test_read_format_zip_malformed.c +++ b/libarchive/test/test_read_format_zip_malformed.c @@ -46,7 +46,7 @@ test_malformed1(void) assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); /* Verify with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); diff --git a/libarchive/test/test_read_format_zip_msdos.c b/libarchive/test/test_read_format_zip_msdos.c index 5f147d55..1867204b 100644 --- a/libarchive/test/test_read_format_zip_msdos.c +++ b/libarchive/test/test_read_format_zip_msdos.c @@ -103,7 +103,7 @@ DEFINE_TEST(test_read_format_zip_msdos) assertEqualInt(ARCHIVE_OK, archive_read_free(a)); /* Verify with streaming reader. */ - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); diff --git a/libarchive/test/test_read_format_zip_nested.c b/libarchive/test/test_read_format_zip_nested.c index 5f6edf26..4418fc4f 100644 --- a/libarchive/test/test_read_format_zip_nested.c +++ b/libarchive/test/test_read_format_zip_nested.c @@ -34,7 +34,7 @@ DEFINE_TEST(test_read_format_zip_nested) struct archive_entry *ae; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* Inspect outer Zip */ assert((a = archive_read_new()) != NULL); diff --git a/libarchive/test/test_read_format_zip_nofiletype.c b/libarchive/test/test_read_format_zip_nofiletype.c index b01afabe..b3260fa7 100644 --- a/libarchive/test/test_read_format_zip_nofiletype.c +++ b/libarchive/test/test_read_format_zip_nofiletype.c @@ -40,7 +40,7 @@ DEFINE_TEST(test_read_format_zip_nofiletype) char data[16]; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a)); diff --git a/libarchive/test/test_read_format_zip_padded.c b/libarchive/test/test_read_format_zip_padded.c index 2094eca3..d8c694ba 100644 --- a/libarchive/test/test_read_format_zip_padded.c +++ b/libarchive/test/test_read_format_zip_padded.c @@ -34,7 +34,7 @@ verify_padded_archive(const char *refname) struct archive_entry *ae; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a)); diff --git a/libarchive/test/test_read_format_zip_sfx.c b/libarchive/test/test_read_format_zip_sfx.c index dc76ef9b..a33c1b80 100644 --- a/libarchive/test/test_read_format_zip_sfx.c +++ b/libarchive/test/test_read_format_zip_sfx.c @@ -37,7 +37,7 @@ DEFINE_TEST(test_read_format_zip_sfx) struct archive_entry *ae; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* Symlinks can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); diff --git a/libarchive/test/test_read_format_zip_with_invalid_traditional_eocd.c b/libarchive/test/test_read_format_zip_with_invalid_traditional_eocd.c index dc94f94f..aca8bed6 100644 --- a/libarchive/test/test_read_format_zip_with_invalid_traditional_eocd.c +++ b/libarchive/test/test_read_format_zip_with_invalid_traditional_eocd.c @@ -39,7 +39,7 @@ DEFINE_TEST(test_read_format_zip_with_invalid_traditional_eocd) struct archive_entry *ae; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a)); diff --git a/libarchive/test/test_read_format_zip_zip64.c b/libarchive/test/test_read_format_zip_zip64.c index ac3789f4..bd2324e5 100644 --- a/libarchive/test/test_read_format_zip_zip64.c +++ b/libarchive/test/test_read_format_zip_zip64.c @@ -88,7 +88,7 @@ DEFINE_TEST(test_read_format_zip_zip64a) size_t s; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* First read with seeking. */ assert((a = archive_read_new()) != NULL); @@ -112,7 +112,7 @@ DEFINE_TEST(test_read_format_zip_zip64b) size_t s; extract_reference_file(refname); - p = slurpfile(&s, refname); + p = slurpfile(&s, "%s", refname); /* First read with seeking. */ assert((a = archive_read_new()) != NULL); diff --git a/libarchive/test/test_read_pax_truncated.c b/libarchive/test/test_read_pax_truncated.c index bc5d74d5..1f6e78ac 100644 --- a/libarchive/test/test_read_pax_truncated.c +++ b/libarchive/test/test_read_pax_truncated.c @@ -82,7 +82,7 @@ DEFINE_TEST(test_read_pax_truncated) assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); goto wrap_up; } else { - failure("Archive truncated to %d bytes", i); + failure("Archive truncated to %zu bytes", i); assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); } @@ -91,7 +91,7 @@ DEFINE_TEST(test_read_pax_truncated) assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, filedata, filedata_size)); goto wrap_up; } else { - failure("Archive truncated to %d bytes", i); + failure("Archive truncated to %zu bytes", i); assertEqualIntA(a, filedata_size, archive_read_data(a, filedata, filedata_size)); } @@ -103,7 +103,7 @@ DEFINE_TEST(test_read_pax_truncated) * does not return an error if it can't consume * it.) */ if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - failure("i=%d minsize=%d", i, + failure("i=%zu minsize=%zu", i, 1536 + 512*((filedata_size + 511)/512) + 512); assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); diff --git a/libarchive/test/test_read_truncated_filter.c b/libarchive/test/test_read_truncated_filter.c index 6cc91e34..632638d6 100644 --- a/libarchive/test/test_read_truncated_filter.c +++ b/libarchive/test/test_read_truncated_filter.c @@ -83,7 +83,7 @@ test_truncation(const char *compression, for (i = 0; i < 100; i++) { sprintf(path, "%s%d", compression, i); archive_entry_copy_pathname(ae, path); - failure(path); + failure("%s", path); if (!assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae))) { archive_write_free(a); @@ -94,7 +94,7 @@ test_truncation(const char *compression, for (j = 0; j < (int)datasize; ++j) { data[j] = (char)(rand() % 256); } - failure(path); + failure("%s", path); if (!assertEqualIntA(a, datasize, archive_write_data(a, data, datasize))) { archive_write_free(a); diff --git a/libarchive/test/test_sparse_basic.c b/libarchive/test/test_sparse_basic.c index 033c052d..0fbb7f7b 100644 --- a/libarchive/test/test_sparse_basic.c +++ b/libarchive/test/test_sparse_basic.c @@ -430,7 +430,7 @@ verify_sparse_file(struct archive *a, const char *path, assert(sparse->type == END); assertEqualInt(expected_offset, archive_entry_size(ae)); - failure(path); + failure("%s", path); assertEqualInt(holes_seen, expected_holes); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); @@ -466,7 +466,7 @@ verify_sparse_file2(struct archive *a, const char *path, /* Verify the number of holes only, not its offset nor its * length because those alignments are deeply dependence on * its filesystem. */ - failure(path); + failure("%s", path); assertEqualInt(blocks, archive_entry_sparse_count(ae)); archive_entry_free(ae); } diff --git a/libarchive/test/test_write_disk.c b/libarchive/test/test_write_disk.c index 60bcdc24..e38dbc78 100644 --- a/libarchive/test/test_write_disk.c +++ b/libarchive/test/test_write_disk.c @@ -186,7 +186,7 @@ static void create_reg_file4(struct archive_entry *ae, const char *msg) #if !defined(_WIN32) || defined(__CYGWIN__) assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); #endif - failure(msg); + failure("%s", msg); assertEqualInt(st.st_size, sizeof(data)); } diff --git a/libarchive/test/test_write_format_cpio_empty.c b/libarchive/test/test_write_format_cpio_empty.c index 60fb2834..2ba415c7 100644 --- a/libarchive/test/test_write_format_cpio_empty.c +++ b/libarchive/test/test_write_format_cpio_empty.c @@ -64,7 +64,7 @@ DEFINE_TEST(test_write_format_cpio_empty) assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - failure("Empty cpio archive should be exactly 87 bytes, was %d.", used); + failure("Empty cpio archive should be exactly 87 bytes, was %zu.", used); assert(used == 87); failure("Empty cpio archive is incorrectly formatted."); assertEqualMem(buff, ref, 87); diff --git a/libarchive/test/test_write_format_shar_empty.c b/libarchive/test/test_write_format_shar_empty.c index 03d70a3b..13794b02 100644 --- a/libarchive/test/test_write_format_shar_empty.c +++ b/libarchive/test/test_write_format_shar_empty.c @@ -49,6 +49,6 @@ DEFINE_TEST(test_write_format_shar_empty) assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); assertEqualInt(ARCHIVE_OK, archive_write_free(a)); - failure("Empty shar archive should be exactly 0 bytes, was %d.", used); + failure("Empty shar archive should be exactly 0 bytes, was %zu.", used); assert(used == 0); } diff --git a/libarchive/test/test_write_format_tar.c b/libarchive/test/test_write_format_tar.c index 3588e8fe..a5ccdc01 100644 --- a/libarchive/test/test_write_format_tar.c +++ b/libarchive/test/test_write_format_tar.c @@ -81,7 +81,7 @@ DEFINE_TEST(test_write_format_tar) /* This calculation gives "the smallest multiple of * the block size that is at least 2048 bytes". */ - failure("blocksize=%d", blocksize); + failure("blocksize=%zu", blocksize); assertEqualInt(((2048 - 1)/blocksize+1)*blocksize, used); /* diff --git a/libarchive/test/test_write_format_tar_sparse.c b/libarchive/test/test_write_format_tar_sparse.c index cc725a9a..54ac0098 100644 --- a/libarchive/test/test_write_format_tar_sparse.c +++ b/libarchive/test/test_write_format_tar_sparse.c @@ -94,7 +94,7 @@ test_1(void) /* This calculation gives "the smallest multiple of * the block size that is at least 11264 bytes". */ - failure("blocksize=%d", blocksize); + failure("blocksize=%zu", blocksize); assertEqualInt(((11264 - 1)/blocksize+1)*blocksize, used); /* @@ -229,7 +229,7 @@ test_2(void) /* This calculation gives "the smallest multiple of * the block size that is at least 11264 bytes". */ - failure("blocksize=%d", blocksize); + failure("blocksize=%zu", blocksize); assertEqualInt(((11264 - 1)/blocksize+1)*blocksize, used); /* diff --git a/libarchive_fe/err.h b/libarchive_fe/err.h index ebf5de81..c663103b 100644 --- a/libarchive_fe/err.h +++ b/libarchive_fe/err.h @@ -35,9 +35,14 @@ #if defined(__GNUC__) && (__GNUC__ > 2 || \ (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) -#define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__printf__, f, a))) +# 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) +# define __LA_PRINTFLIKE(f,a) #endif void lafe_warnc(int code, const char *fmt, ...) __LA_PRINTFLIKE(2, 3); diff --git a/tar/test/test_basic.c b/tar/test/test_basic.c index 9bb966a0..b1c49834 100644 --- a/tar/test/test_basic.c +++ b/tar/test/test_basic.c @@ -96,7 +96,7 @@ run_tar(const char *target, const char *pack_options, /* Use the tar program to create an archive. */ r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); - failure("Error invoking %s cf -", testprog, pack_options); + failure("Error invoking %s cf -%s", testprog, pack_options); assertEqualInt(r, 0); assertChdir(target); diff --git a/tar/test/test_copy.c b/tar/test/test_copy.c index b828666b..d618e45c 100644 --- a/tar/test/test_copy.c +++ b/tar/test/test_copy.c @@ -256,13 +256,13 @@ verify_tree(size_t limit) continue; switch(dp[0]) { case 'l': case 'm': case 'd': - failure("strlen(p)=%d", strlen(p)); + failure("strlen(p)=%zu", strlen(p)); assert(strlen(p) < limit); assertEqualString(p, filenames[strlen(p)]); break; case 'f': case 's': - failure("strlen(p)=%d", strlen(p)); + failure("strlen(p)=%zu", strlen(p)); assert(strlen(p) < limit + 1); assertEqualString(p, filenames[strlen(p)]); diff --git a/tar/test/test_option_C_upper.c b/tar/test/test_option_C_upper.c index dae98544..538890f5 100644 --- a/tar/test/test_option_C_upper.c +++ b/tar/test/test_option_C_upper.c @@ -117,7 +117,7 @@ DEFINE_TEST(test_option_C_upper) assertMakeDir("test6", 0755); assertChdir("test6"); r = systemf("%s -cf archive.tar -C XXX -C ../d1 file1 2>write.err", - testprog, testworkdir); + testprog); assert(r != 0); assertNonEmptyFile("write.err"); assertEqualInt(0, diff --git a/tar/test/test_option_s.c b/tar/test/test_option_s.c index 09c72ee7..fa799a29 100644 --- a/tar/test/test_option_s.c +++ b/tar/test/test_option_s.c @@ -92,10 +92,8 @@ DEFINE_TEST(test_option_s) * Test 5: Name-switching substitutions when extracting archive. */ assertMakeDir("test5", 0755); - systemf("%s -cf test5.tar in/d1/foo in/d1/bar", - testprog, testprog); - systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5", - testprog, testprog); + systemf("%s -cf test5.tar in/d1/foo in/d1/bar", testprog); + systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5", testprog); assertFileContents("foo", 3, "test5/in/d1/bar"); assertFileContents("bar", 3, "test5/in/d1/foo"); 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); |