From 1be3e0a24d62e0d5227f148400be5ae961c65509 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Sun, 29 Dec 2024 10:18:06 -0800 Subject: [PATCH] Add more casts for %o (#2461) (cherry picked from commit a2086b67d88d8d3d2d99d80ada3fcd19eaf76ed4) --- libarchive/archive_write_add_filter_b64encode.c | 2 +- libarchive/archive_write_add_filter_uuencode.c | 2 +- libarchive/archive_write_disk_posix.c | 5 +++-- test_utils/test_main.c | 16 +++++++++------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libarchive/archive_write_add_filter_b64encode.c b/libarchive/archive_write_add_filter_b64encode.c index 2c361bfb9..dbedf9d30 100644 --- a/libarchive/archive_write_add_filter_b64encode.c +++ b/libarchive/archive_write_add_filter_b64encode.c @@ -166,7 +166,7 @@ archive_filter_b64encode_open(struct archive_write_filter *f) } archive_string_sprintf(&state->encoded_buff, "begin-base64 %o %s\n", - state->mode, state->name.s); + (unsigned int)state->mode, state->name.s); f->data = state; return (0); diff --git a/libarchive/archive_write_add_filter_uuencode.c b/libarchive/archive_write_add_filter_uuencode.c index 50bfeb6ea..99c7a2cb7 100644 --- a/libarchive/archive_write_add_filter_uuencode.c +++ b/libarchive/archive_write_add_filter_uuencode.c @@ -155,7 +155,7 @@ archive_filter_uuencode_open(struct archive_write_filter *f) } archive_string_sprintf(&state->encoded_buff, "begin %o %s\n", - state->mode, state->name.s); + (unsigned int)state->mode, state->name.s); f->data = state; return (0); diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index d69ab34e8..899f50f50 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -3803,7 +3803,8 @@ set_mode(struct archive_write_disk *a, int mode) break; default: archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); + "Can't set permissions to 0%o", + (unsigned int)mode); r = ARCHIVE_WARN; } } @@ -3826,7 +3827,7 @@ set_mode(struct archive_write_disk *a, int mode) if (r2 != 0) { archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); + "Can't set permissions to 0%o", (unsigned int)mode); r = ARCHIVE_WARN; } } diff --git a/test_utils/test_main.c b/test_utils/test_main.c index de6a6107a..abd99b5da 100644 --- a/test_utils/test_main.c +++ b/test_utils/test_main.c @@ -613,7 +613,8 @@ assertion_chmod(const char *file, int line, const char *pathname, int mode) assertion_count(file, line); if (chmod(pathname, mode) == 0) return (1); - failure_start(file, line, "chmod(\"%s\", %4.o)", pathname, mode); + failure_start(file, line, "chmod(\"%s\", %4.o)", pathname, + (unsigned int)mode); failure_finish(NULL); return (0); @@ -1602,7 +1603,7 @@ assertion_file_mode(const char *file, int line, const char *pathname, int expect if (r == 0 && mode == expected_mode) return (1); failure_start(file, line, "File %s has mode %o, expected %o", - pathname, mode, expected_mode); + pathname, (unsigned int)mode, (unsigned int)expected_mode); #endif failure_finish(NULL); return (0); @@ -1712,8 +1713,8 @@ assertion_is_dir(const char *file, int line, const char *pathname, int mode) /* TODO: Can we do better here? */ if (mode >= 0 && (mode_t)mode != (st.st_mode & 07777)) { failure_start(file, line, "Dir %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); + logprintf(" Expected: 0%3o\n", (unsigned int)mode); + logprintf(" Found: 0%3o\n", (unsigned int)st.st_mode & 07777); failure_finish(NULL); return (0); } @@ -1745,8 +1746,8 @@ assertion_is_reg(const char *file, int line, const char *pathname, int mode) /* TODO: Can we do better here? */ if (mode >= 0 && (mode_t)mode != (st.st_mode & 07777)) { failure_start(file, line, "File %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); + logprintf(" Expected: 0%3o\n", (unsigned int)mode); + logprintf(" Found: 0%3o\n", (unsigned int)st.st_mode & 07777); failure_finish(NULL); return (0); } @@ -3466,7 +3467,8 @@ assertion_entry_compare_acls(const char *file, int line, if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0 && (mode_t)(mode & 0777) != (archive_entry_mode(ae) & 0777)) { failure_start(file, line, "Mode (%02o) and entry mode (%02o) " - "mismatch", mode, archive_entry_mode(ae)); + "mismatch", (unsigned int)mode, + (unsigned int)archive_entry_mode(ae)); failure_finish(NULL); ret = 1; } -- 2.47.3