From d0a8792610601a140b97f4d4c6a6af0a12eb0a65 Mon Sep 17 00:00:00 2001 From: Michihiro NAKAJIMA Date: Mon, 21 Dec 2009 19:39:58 -0500 Subject: [PATCH] Eliminate warnings on Visual Studio 10 W64. On Win64, the size of 'int' is stil 4 bytes and the size of 'size_t' is 8 bytes. A conversion from 'size_t' to 'int', causes warning with compiling. SVN-Revision: 1772 --- cpio/cpio_windows.c | 4 ++-- libarchive/archive_entry.c | 4 ++-- libarchive/archive_read_support_compression_program.c | 2 +- libarchive/archive_read_support_format_mtree.c | 2 +- libarchive/archive_read_support_format_tar.c | 2 +- libarchive/archive_windows.c | 10 +++++----- libarchive/archive_write_set_compression_compress.c | 2 +- libarchive/archive_write_set_format_cpio.c | 5 +++-- libarchive/archive_write_set_format_cpio_newc.c | 5 +++-- libarchive/archive_write_set_format_mtree.c | 2 +- libarchive/archive_write_set_format_pax.c | 9 +++++---- libarchive/archive_write_set_format_zip.c | 6 +++--- tar/bsdtar_windows.c | 4 ++-- tar/util.c | 4 ++-- 14 files changed, 32 insertions(+), 29 deletions(-) diff --git a/cpio/cpio_windows.c b/cpio/cpio_windows.c index 841e94928..420e01d5e 100644 --- a/cpio/cpio_windows.c +++ b/cpio/cpio_windows.c @@ -61,10 +61,10 @@ permissive_name(const char *name) { wchar_t *wn, *wnp; wchar_t *ws, *wsp; - size_t l, len, slen, alloclen; + DWORD l, len, slen, alloclen; int unc; - len = strlen(name); + len = (DWORD)strlen(name); wn = malloc((len + 1) * sizeof(wchar_t)); if (wn == NULL) return (NULL); diff --git a/libarchive/archive_entry.c b/libarchive/archive_entry.c index 4a3ce266c..00025e7eb 100644 --- a/libarchive/archive_entry.c +++ b/libarchive/archive_entry.c @@ -222,7 +222,7 @@ static const wchar_t * aes_get_wcs(struct aes *aes) { wchar_t *w; - int r; + size_t r; /* Return WCS form if we already have it. */ if (aes->aes_set & AES_SET_WCS) @@ -240,7 +240,7 @@ aes_get_wcs(struct aes *aes) if (w == NULL) __archive_errx(1, "No memory for aes_get_wcs()"); r = mbstowcs(w, aes->aes_mbs.s, wcs_length); - if (r > 0) { + if (r != (size_t)-1 && r != 0) { w[r] = 0; aes->aes_set |= AES_SET_WCS; return (aes->aes_wcs = w); diff --git a/libarchive/archive_read_support_compression_program.c b/libarchive/archive_read_support_compression_program.c index f9b2cc611..3115b5c56 100644 --- a/libarchive/archive_read_support_compression_program.c +++ b/libarchive/archive_read_support_compression_program.c @@ -205,7 +205,7 @@ program_bidder_bid(struct archive_read_filter_bidder *self, /* No match, so don't bid. */ if (memcmp(p, state->signature, state->signature_len) != 0) return (0); - return (state->signature_len * 8); + return ((int)state->signature_len * 8); } /* Otherwise, bid once and then never bid again. */ diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 167ff3e86..8d88d7815 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -196,7 +196,7 @@ mtree_bid(struct archive_read *a) return (-1); if (strncmp(p, signature, strlen(signature)) == 0) - return (8 * strlen(signature)); + return (8 * (int)strlen(signature)); return (0); } diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c index 79ab246c8..fb5a7851d 100644 --- a/libarchive/archive_read_support_format_tar.c +++ b/libarchive/archive_read_support_format_tar.c @@ -2318,7 +2318,7 @@ base64_decode(const char *s, size_t len, size_t *out_len) /* If the decode table is not yet initialized, prepare it. */ if (decode_table[digits[1]] != 1) { - size_t i; + unsigned i; memset(decode_table, 0xff, sizeof(decode_table)); for (i = 0; i < sizeof(digits); i++) decode_table[digits[i]] = i; diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index f938ca0a9..03a459e7c 100644 --- a/libarchive/archive_windows.c +++ b/libarchive/archive_windows.c @@ -125,14 +125,14 @@ permissive_name(const char *name) { wchar_t *wn, *wnp; wchar_t *ws, *wsp; - size_t l, len, slen; + DWORD l, len, slen; int unc; - len = strlen(name); + len = (DWORD)strlen(name); wn = malloc((len + 1) * sizeof(wchar_t)); if (wn == NULL) return (NULL); - l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len); + l = MultiByteToWideChar(CP_ACP, 0, name, (int)len, wn, (int)len); if (l == 0) { free(wn); return (NULL); @@ -323,8 +323,8 @@ __link(const char *src, const char *dst) else wcscat(wnewsrc, L"\\"); /* Converting multi-byte src to wide-char src */ - wlen = wcslen(wsrc); - slen = strlen(src); + wlen = (int)wcslen(wsrc); + slen = (int)strlen(src); n = MultiByteToWideChar(CP_ACP, 0, src, slen, wsrc, wlen); if (n == 0) { free (wnewsrc); diff --git a/libarchive/archive_write_set_compression_compress.c b/libarchive/archive_write_set_compression_compress.c index be1902692..158c06a84 100644 --- a/libarchive/archive_write_set_compression_compress.c +++ b/libarchive/archive_write_set_compression_compress.c @@ -425,7 +425,7 @@ archive_compressor_compress_finish(struct archive_write *a) ssize_t block_length, target_block_length, bytes_written; int ret; struct private_data *state; - unsigned tocopy; + size_t tocopy; state = (struct private_data *)a->compressor.data; if (a->client_writer == NULL) { diff --git a/libarchive/archive_write_set_format_cpio.c b/libarchive/archive_write_set_format_cpio.c index bddb529ee..ab7897c0c 100644 --- a/libarchive/archive_write_set_format_cpio.c +++ b/libarchive/archive_write_set_format_cpio.c @@ -187,7 +187,7 @@ archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry) ret2 = ARCHIVE_OK; path = archive_entry_pathname(entry); - pathlength = strlen(path) + 1; /* Include trailing null. */ + pathlength = (int)strlen(path) + 1; /* Include trailing null. */ memset(&h, 0, sizeof(h)); format_octal(070707, &h.c_magic, sizeof(h.c_magic)); @@ -327,7 +327,8 @@ static int archive_write_cpio_finish_entry(struct archive_write *a) { struct cpio *cpio; - int to_write, ret; + size_t to_write; + int ret; cpio = (struct cpio *)a->format_data; ret = ARCHIVE_OK; diff --git a/libarchive/archive_write_set_format_cpio_newc.c b/libarchive/archive_write_set_format_cpio_newc.c index 9dbfbbba5..641c883dd 100644 --- a/libarchive/archive_write_set_format_cpio_newc.c +++ b/libarchive/archive_write_set_format_cpio_newc.c @@ -125,7 +125,7 @@ archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) ret2 = ARCHIVE_OK; path = archive_entry_pathname(entry); - pathlength = strlen(path) + 1; /* Include trailing null. */ + pathlength = (int)strlen(path) + 1; /* Include trailing null. */ memset(&h, 0, sizeof(h)); format_hex(0x070701, &h.c_magic, sizeof(h.c_magic)); @@ -278,7 +278,8 @@ static int archive_write_newc_finish_entry(struct archive_write *a) { struct cpio *cpio; - int to_write, ret; + size_t to_write; + int ret; cpio = (struct cpio *)a->format_data; while (cpio->entry_bytes_remaining > 0) { diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index b01f80c60..1b46147a6 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -854,7 +854,7 @@ archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) * Compute a POSIX 1003.2 checksum */ const unsigned char *p; - int nn; + size_t nn; for (nn = n, p = buff; nn--; ++p) COMPUTE_CRC(mtree->crc, *p); diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index ae3b2b5ae..2d10db1b3 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -307,7 +307,7 @@ add_pax_attr(struct archive_string *as, const char *key, const char *value) * PAX attributes have the following layout: * <=> */ - len = 1 + strlen(key) + 1 + strlen(value) + 1; + len = 1 + (int)strlen(key) + 1 + (int)strlen(value) + 1; /* * The field includes the length of the field, so @@ -362,7 +362,7 @@ archive_write_pax_header_xattrs(struct pax *pax, struct archive_entry *entry) url_encoded_name = url_encode(name); if (url_encoded_name != NULL) { /* Convert narrow-character to wide-character. */ - int wcs_length = strlen(url_encoded_name); + size_t wcs_length = strlen(url_encoded_name); wcs_name = (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t)); if (wcs_name == NULL) __archive_errx(1, "No memory for xattr conversion"); @@ -1025,7 +1025,7 @@ build_ustar_entry_name(char *dest, const char *src, size_t src_length, char *p; int need_slash = 0; /* Was there a trailing slash? */ size_t suffix_length = 99; - int insert_length; + size_t insert_length; /* Length of additional dir element to be added. */ if (insert == NULL) @@ -1249,7 +1249,8 @@ archive_write_pax_finish_entry(struct archive_write *a) static int write_nulls(struct archive_write *a, size_t padding) { - int ret, to_write; + int ret; + size_t to_write; while (padding > 0) { to_write = padding < a->null_length ? padding : a->null_length; diff --git a/libarchive/archive_write_set_format_zip.c b/libarchive/archive_write_set_format_zip.c index 4c19b8e0d..877ae0931 100644 --- a/libarchive/archive_write_set_format_zip.c +++ b/libarchive/archive_write_set_format_zip.c @@ -329,7 +329,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) archive_le16enc(&h.flags, ZIP_FLAGS); archive_le16enc(&h.compression, zip->compression); archive_le32enc(&h.timedate, dos_time(archive_entry_mtime(entry))); - archive_le16enc(&h.filename_length, path_length(entry)); + archive_le16enc(&h.filename_length, (uint16_t)path_length(entry)); switch (zip->compression) { case COMPRESSION_STORE: @@ -530,7 +530,7 @@ archive_write_zip_finish(struct archive_write *a) archive_le32enc(&h.crc32, l->crc32); archive_le32enc(&h.compressed_size, l->compressed_size); archive_le32enc(&h.uncompressed_size, archive_entry_size(l->entry)); - archive_le16enc(&h.filename_length, path_length(l->entry)); + archive_le16enc(&h.filename_length, (uint16_t)path_length(l->entry)); archive_le16enc(&h.extra_length, sizeof(e)); archive_le16enc(&h.attributes_external[2], archive_entry_mode(l->entry)); archive_le32enc(&h.offset, l->offset); @@ -663,5 +663,5 @@ write_path(struct archive_entry *entry, struct archive_write *archive) written_bytes += 1; } - return written_bytes; + return ((int)written_bytes); } diff --git a/tar/bsdtar_windows.c b/tar/bsdtar_windows.c index 5fc2d9fd6..4d1205028 100644 --- a/tar/bsdtar_windows.c +++ b/tar/bsdtar_windows.c @@ -62,10 +62,10 @@ permissive_name(const char *name) { wchar_t *wn, *wnp; wchar_t *ws, *wsp; - size_t l, len, slen, alloclen; + DWORD l, len, slen, alloclen; int unc; - len = strlen(name); + len = (DWORD)strlen(name); wn = malloc((len + 1) * sizeof(wchar_t)); if (wn == NULL) return (NULL); diff --git a/tar/util.c b/tar/util.c index 6a4b3f266..5a32c361b 100644 --- a/tar/util.c +++ b/tar/util.c @@ -149,13 +149,13 @@ safe_fprintf(FILE *f, const char *fmt, ...) } else { /* Not printable, format the bytes. */ while (n-- > 0) - i += bsdtar_expand_char( + i += (unsigned)bsdtar_expand_char( outbuff, i, *p++); } } else { /* After any conversion failure, don't bother * trying to convert the rest. */ - i += bsdtar_expand_char(outbuff, i, *p++); + i += (unsigned)bsdtar_expand_char(outbuff, i, *p++); try_wc = 0; } -- 2.47.3