From: Michihiro NAKAJIMA Date: Sat, 18 Feb 2012 19:48:38 +0000 (+0900) Subject: On Visual Studio, Enable Warning 4244: 'conversion' conversion from 'type1' X-Git-Tag: v3.0.4~2^2~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d2cbbc56c5db48705a23aa80d256fcd92d69e6f;p=thirdparty%2Flibarchive.git On Visual Studio, Enable Warning 4244: 'conversion' conversion from 'type1' to 'type2', possible lose of data. --- diff --git a/libarchive/archive_endian.h b/libarchive/archive_endian.h index edc90ee6a..68123b0dd 100644 --- a/libarchive/archive_endian.h +++ b/libarchive/archive_endian.h @@ -126,8 +126,8 @@ archive_be64enc(void *pp, uint64_t u) { unsigned char *p = (unsigned char *)pp; - archive_be32enc(p, u >> 32); - archive_be32enc(p + 4, u & 0xffffffff); + archive_be32enc(p, (uint32_t)(u >> 32)); + archive_be32enc(p + 4, (uint32_t)(u & 0xffffffff)); } static inline void @@ -155,8 +155,8 @@ archive_le64enc(void *pp, uint64_t u) { unsigned char *p = (unsigned char *)pp; - archive_le32enc(p, u & 0xffffffff); - archive_le32enc(p + 4, u >> 32); + archive_le32enc(p, (uint32_t)(u & 0xffffffff)); + archive_le32enc(p + 4, (uint32_t)(u >> 32)); } #endif diff --git a/libarchive/archive_entry_link_resolver.c b/libarchive/archive_entry_link_resolver.c index a18144dd5..07f0d362e 100644 --- a/libarchive/archive_entry_link_resolver.c +++ b/libarchive/archive_entry_link_resolver.c @@ -362,7 +362,7 @@ insert_entry(struct archive_entry_linkresolver *res, if (res->number_entries > res->number_buckets * 2) grow_hash(res); - hash = archive_entry_dev(entry) ^ archive_entry_ino64(entry); + hash = (size_t)(archive_entry_dev(entry) ^ archive_entry_ino64(entry)); bucket = hash & (res->number_buckets - 1); /* If we could allocate the entry, record it. */ diff --git a/libarchive/archive_entry_stat.c b/libarchive/archive_entry_stat.c index 65ff1cf92..71a407b1f 100644 --- a/libarchive/archive_entry_stat.c +++ b/libarchive/archive_entry_stat.c @@ -70,12 +70,12 @@ archive_entry_stat(struct archive_entry *entry) st->st_ctime = archive_entry_ctime(entry); st->st_mtime = archive_entry_mtime(entry); st->st_dev = archive_entry_dev(entry); - st->st_gid = archive_entry_gid(entry); - st->st_uid = archive_entry_uid(entry); - st->st_ino = archive_entry_ino64(entry); + st->st_gid = (gid_t)archive_entry_gid(entry); + st->st_uid = (uid_t)archive_entry_uid(entry); + st->st_ino = (ino_t)archive_entry_ino64(entry); st->st_nlink = archive_entry_nlink(entry); st->st_rdev = archive_entry_rdev(entry); - st->st_size = archive_entry_size(entry); + st->st_size = (off_t)archive_entry_size(entry); st->st_mode = archive_entry_mode(entry); /* diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index 987295f02..42eb06192 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -638,8 +638,8 @@ archive_read_data(struct archive *_a, void *buff, size_t s) len = s; } else if (a->read_data_output_offset < a->read_data_offset) { - len = a->read_data_offset - - a->read_data_output_offset; + len = (size_t)(a->read_data_offset - + a->read_data_output_offset); } else len = 0; @@ -1231,7 +1231,7 @@ advance_file_pointer(struct archive_read_filter *filter, int64_t request) /* Use up the copy buffer first. */ if (filter->avail > 0) { - min = minimum(request, (int64_t)filter->avail); + min = (size_t)minimum(request, (int64_t)filter->avail); filter->next += min; filter->avail -= min; request -= min; @@ -1241,7 +1241,7 @@ advance_file_pointer(struct archive_read_filter *filter, int64_t request) /* Then use up the client buffer. */ if (filter->client_avail > 0) { - min = minimum(request, (int64_t)filter->client_avail); + min = (size_t)minimum(request, (int64_t)filter->client_avail); filter->client_next += min; filter->client_avail -= min; request -= min; @@ -1283,7 +1283,7 @@ advance_file_pointer(struct archive_read_filter *filter, int64_t request) if (bytes_read >= request) { filter->client_next = ((const char *)filter->client_buff) + request; - filter->client_avail = bytes_read - request; + filter->client_avail = (size_t)(bytes_read - request); filter->client_total = bytes_read; total_bytes_skipped += request; filter->position += request; diff --git a/libarchive/archive_read_disk_windows.c b/libarchive/archive_read_disk_windows.c index ecd3d438b..b404d03b5 100644 --- a/libarchive/archive_read_disk_windows.c +++ b/libarchive/archive_read_disk_windows.c @@ -552,7 +552,7 @@ trivial_lookup_uname(void *private_data, int64_t uid) static int64_t align_num_per_sector(struct tree *t, int64_t size) { - int surplus; + int64_t surplus; size += t->current_filesystem->bytesPerSector -1; surplus = size % t->current_filesystem->bytesPerSector; @@ -599,7 +599,7 @@ start_next_async_read(struct archive_read_disk *a, struct tree *t) buffbytes = olp->buff_size; if (buffbytes > t->current_sparse->length) - buffbytes = t->current_sparse->length; + buffbytes = (DWORD)t->current_sparse->length; /* Skip hole. */ if (t->current_sparse->offset > t->ol_total) { @@ -615,7 +615,7 @@ start_next_async_read(struct archive_read_disk *a, struct tree *t) olp->bytes_expected = buffbytes; t->ol_remaining_bytes -= buffbytes; } else { - olp->bytes_expected = t->ol_remaining_bytes; + olp->bytes_expected = (size_t)t->ol_remaining_bytes; t->ol_remaining_bytes = 0; } olp->bytes_transferred = 0; diff --git a/libarchive/archive_read_open_fd.c b/libarchive/archive_read_open_fd.c index d8f657295..797284197 100644 --- a/libarchive/archive_read_open_fd.c +++ b/libarchive/archive_read_open_fd.c @@ -129,8 +129,8 @@ static int64_t file_skip(struct archive *a, void *client_data, int64_t request) { struct read_fd_data *mine = (struct read_fd_data *)client_data; - off_t skip = (off_t)request; - off_t old_offset, new_offset; + int64_t skip = request; + int64_t old_offset, new_offset; int skip_bits = sizeof(skip) * 8 - 1; /* off_t is a signed type. */ if (!mine->use_lseek) diff --git a/libarchive/archive_read_open_filename.c b/libarchive/archive_read_open_filename.c index cad2fd1eb..69c44ea7e 100644 --- a/libarchive/archive_read_open_filename.c +++ b/libarchive/archive_read_open_filename.c @@ -454,7 +454,7 @@ static int64_t file_seek(struct archive *a, void *client_data, int64_t request, int whence) { struct read_file_data *mine = (struct read_file_data *)client_data; - off_t r; + int64_t r; /* We use off_t here because lseek() is declared that way. */ /* See above for notes about when off_t is less than 64 bits. */ diff --git a/libarchive/archive_read_private.h b/libarchive/archive_read_private.h index 76d0b91d9..445c557f3 100644 --- a/libarchive/archive_read_private.h +++ b/libarchive/archive_read_private.h @@ -134,8 +134,8 @@ struct archive_read { /* Dev/ino of the archive being read/written. */ int skip_file_set; - dev_t skip_file_dev; - ino_t skip_file_ino; + int64_t skip_file_dev; + int64_t skip_file_ino; /* * Used by archive_read_data() to track blocks and copy diff --git a/libarchive/archive_read_support_filter_rpm.c b/libarchive/archive_read_support_filter_rpm.c index 7dbfc0ebc..1b3e12420 100644 --- a/libarchive/archive_read_support_filter_rpm.c +++ b/libarchive/archive_read_support_filter_rpm.c @@ -188,7 +188,7 @@ rpm_filter_read(struct archive_read_filter *self, const void **buff) if (rpm->total_in + avail_in < RPM_LEAD_SIZE) used += avail_in; else { - n = RPM_LEAD_SIZE - rpm->total_in; + n = (size_t)(RPM_LEAD_SIZE - rpm->total_in); used += n; b += n; rpm->state = ST_HEADER; diff --git a/libarchive/archive_read_support_format_7zip.c b/libarchive/archive_read_support_format_7zip.c index 6281f93c6..1e02467f4 100644 --- a/libarchive/archive_read_support_format_7zip.c +++ b/libarchive/archive_read_support_format_7zip.c @@ -580,7 +580,7 @@ archive_read_format_7zip_read_header(struct archive_read *a, free_Header(&header); if (r != ARCHIVE_OK) return (r); - zip->entries_remaining = zip->numFiles; + zip->entries_remaining = (size_t)zip->numFiles; zip->entry = zip->entries; } else { ++zip->entry; @@ -715,7 +715,8 @@ archive_read_format_7zip_read_data(struct archive_read *a, return (ARCHIVE_EOF); } - bytes = read_stream(a, buff, zip->entry_bytes_remaining, 0); + bytes = read_stream(a, buff, + (size_t)zip->entry_bytes_remaining, 0); if (bytes < 0) return ((int)bytes); if (bytes == 0) { @@ -773,7 +774,7 @@ archive_read_format_7zip_read_data_skip(struct archive_read *a) * If the length is at the beginning, we can skip the * compressed data much more quickly. */ - bytes_skipped = skip_stream(a, zip->entry_bytes_remaining); + bytes_skipped = skip_stream(a, (size_t)zip->entry_bytes_remaining); if (bytes_skipped < 0) return (ARCHIVE_FATAL); zip->entry_bytes_remaining = 0; @@ -1053,7 +1054,7 @@ init_decompression(struct archive_read *a, struct _7zip *zip, ff = &filters[fi]; #endif r = lzma_properties_decode(&filters[fi], NULL, - coder1->properties, coder1->propertiesSize); + coder1->properties, (size_t)coder1->propertiesSize); if (r != LZMA_OK) { set_error(a, r); return (ARCHIVE_FAILED); @@ -1441,8 +1442,8 @@ decompress(struct archive_read *a, struct _7zip *zip, } while (zip->ppstream.avail_out && (zip->ppstream.avail_in || flush_bytes)); - t_avail_in = zip->ppstream.avail_in; - t_avail_out = zip->ppstream.avail_out; + t_avail_in = (size_t)zip->ppstream.avail_in; + t_avail_out = (size_t)zip->ppstream.avail_out; break; } default: @@ -1675,8 +1676,8 @@ read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi) return (0); if (*p != kSize) return (-1); - pi->sizes = calloc(pi->numPackStreams, sizeof(uint64_t)); - pi->positions = calloc(pi->numPackStreams, sizeof(uint64_t)); + pi->sizes = calloc((size_t)pi->numPackStreams, sizeof(uint64_t)); + pi->positions = calloc((size_t)pi->numPackStreams, sizeof(uint64_t)); if (pi->sizes == NULL || pi->positions == NULL) return (-1); @@ -1693,9 +1694,9 @@ read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi) if (*p == kEnd) { /* PackStreamDigests[num] are not present. */ pi->digest.defineds = - calloc(pi->numPackStreams, sizeof(*pi->digest.defineds)); + calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.defineds)); pi->digest.digests = - calloc(pi->numPackStreams, sizeof(*pi->digest.digests)); + calloc((size_t)pi->numPackStreams, sizeof(*pi->digest.digests)); if (pi->digest.defineds == NULL || pi->digest.digests == NULL) return (-1); return (0); @@ -1704,7 +1705,7 @@ read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi) if (*p != kSize) return (-1); - if (read_Digests(a, &(pi->digest), pi->numPackStreams) < 0) + if (read_Digests(a, &(pi->digest), (size_t)pi->numPackStreams) < 0) return (-1); /* @@ -1753,7 +1754,7 @@ read_Folder(struct archive_read *a, struct _7z_folder *f) /* Too many coders. */ return (-1); - f->coders = calloc(f->numCoders, sizeof(*f->coders)); + f->coders = calloc((size_t)f->numCoders, sizeof(*f->coders)); if (f->coders == NULL) return (-1); for (i = 0; i< f->numCoders; i++) { @@ -1805,14 +1806,14 @@ read_Folder(struct archive_read *a, struct _7z_folder *f) a, &(f->coders[i].propertiesSize)) < 0) return (-1); if ((p = header_bytes( - a, f->coders[i].propertiesSize)) == NULL) + a, (size_t)f->coders[i].propertiesSize)) == NULL) return (-1); f->coders[i].properties = - malloc(f->coders[i].propertiesSize); + malloc((size_t)f->coders[i].propertiesSize); if (f->coders[i].properties == NULL) return (-1); memcpy(f->coders[i].properties, p, - f->coders[i].propertiesSize); + (size_t)f->coders[i].propertiesSize); } numInStreamsTotal += f->coders[i].numInStreams; @@ -1827,7 +1828,8 @@ read_Folder(struct archive_read *a, struct _7z_folder *f) if (zip->header_bytes_remaining < f->numBindPairs) return (-1); if (f->numBindPairs > 0) { - f->bindPairs = calloc(f->numBindPairs, sizeof(*f->bindPairs)); + f->bindPairs = + calloc((size_t)f->numBindPairs, sizeof(*f->bindPairs)); if (f->bindPairs == NULL) return (-1); } else @@ -1845,7 +1847,7 @@ read_Folder(struct archive_read *a, struct _7z_folder *f) f->numPackedStreams = numInStreamsTotal - f->numBindPairs; f->packedStreams = - calloc(f->numPackedStreams, sizeof(*f->packedStreams)); + calloc((size_t)f->numPackedStreams, sizeof(*f->packedStreams)); if (f->packedStreams == NULL) return (-1); if (f->numPackedStreams == 1) { @@ -1917,7 +1919,8 @@ read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci) goto failed; switch (*p) { case 0: - ci->folders = calloc(ci->numFolders, sizeof(*ci->folders)); + ci->folders = + calloc((size_t)ci->numFolders, sizeof(*ci->folders)); if (ci->folders == NULL) return (-1); for (i = 0; i < ci->numFolders; i++) { @@ -1943,7 +1946,7 @@ read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci) unsigned j; folder->unPackSize = - calloc(folder->numOutStreams, sizeof(*folder->unPackSize)); + calloc((size_t)folder->numOutStreams, sizeof(*folder->unPackSize)); if (folder->unPackSize == NULL) goto failed; for (j = 0; j < folder->numOutStreams; j++) { @@ -1961,7 +1964,7 @@ read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci) return (0); if (*p != kCRC) goto failed; - if (read_Digests(a, &digest, ci->numFolders) < 0) + if (read_Digests(a, &digest, (size_t)ci->numFolders) < 0) goto failed; for (i = 0; i < ci->numFolders; i++) { ci->folders[i].digest_defined = digest.defineds[i]; @@ -1985,8 +1988,8 @@ failed: static uint64_t folder_uncompressed_size(struct _7z_folder *f) { - int n = f->numOutStreams; - unsigned pairs = f->numBindPairs; + int n = (int)f->numOutStreams; + unsigned pairs = (unsigned)f->numBindPairs; while (--n >= 0) { unsigned i; @@ -2035,7 +2038,7 @@ read_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss, return (-1); if (1000000 < f[i].numUnpackStreams) return (-1); - unpack_streams += f[i].numUnpackStreams; + unpack_streams += (size_t)f[i].numUnpackStreams; } if ((p = header_bytes(a, 1)) == NULL) return (-1); @@ -2089,7 +2092,7 @@ read_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss, numDigests = 0; for (i = 0; i < numFolders; i++) { if (f[i].numUnpackStreams != 1 || !f[i].digest_defined) - numDigests += f[i].numUnpackStreams; + numDigests += (uint32_t)f[i].numUnpackStreams; } if (type == kCRC) { @@ -2187,7 +2190,7 @@ read_StreamsInfo(struct archive_read *a, struct _7z_stream_info *si) f = si->ci.folders; for (i = 0; i < si->ci.numFolders; i++) { f[i].packIndex = packIndex; - packIndex += f[i].numPackedStreams; + packIndex += (uint32_t)f[i].numPackedStreams; if (packIndex > si->pi.numPackStreams) return (-1); } @@ -2197,7 +2200,7 @@ read_StreamsInfo(struct archive_read *a, struct _7z_stream_info *si) if (*p == kSubStreamsInfo) { if (read_SubStreamsInfo(a, &(si->ss), - si->ci.folders, si->ci.numFolders) < 0) + si->ci.folders, (size_t)si->ci.numFolders) < 0) return (-1); if ((p = header_bytes(a, 1)) == NULL) return (-1); @@ -2285,7 +2288,7 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, if (1000000 < zip->numFiles) return (-1); - zip->entries = calloc(zip->numFiles, sizeof(*zip->entries)); + zip->entries = calloc((size_t)zip->numFiles, sizeof(*zip->entries)); if (zip->entries == NULL) return (-1); entries = zip->entries; @@ -2310,12 +2313,12 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, switch (type) { case kEmptyStream: - h->emptyStreamBools = calloc(zip->numFiles, + h->emptyStreamBools = calloc((size_t)zip->numFiles, sizeof(*h->emptyStreamBools)); if (h->emptyStreamBools == NULL) return (-1); if (read_Bools( - a, h->emptyStreamBools, zip->numFiles) < 0) + a, h->emptyStreamBools, (size_t)zip->numFiles) < 0) return (-1); empty_streams = 0; for (i = 0; i < zip->numFiles; i++) { @@ -2422,15 +2425,15 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, if ((p = header_bytes(a, 2)) == NULL) return (-1); allAreDefined = *p; - h->attrBools = calloc(zip->numFiles, + h->attrBools = calloc((size_t)zip->numFiles, sizeof(*h->attrBools)); if (h->attrBools == NULL) return (-1); if (allAreDefined) - memset(h->attrBools, 1, zip->numFiles); + memset(h->attrBools, 1, (size_t)zip->numFiles); else { if (read_Bools(a, h->attrBools, - zip->numFiles) < 0) + (size_t)zip->numFiles) < 0) return (-1); } for (i = 0; i < zip->numFiles; i++) { @@ -2560,7 +2563,7 @@ read_Times(struct archive_read *a, struct _7z_header_info *h, int type) int allAreDefined; unsigned i; - timeBools = calloc(zip->numFiles, sizeof(*timeBools)); + timeBools = calloc((size_t)zip->numFiles, sizeof(*timeBools)); if (timeBools == NULL) return (-1); @@ -2569,9 +2572,9 @@ read_Times(struct archive_read *a, struct _7z_header_info *h, int type) goto failed; allAreDefined = *p; if (allAreDefined) - memset(timeBools, 1, zip->numFiles); + memset(timeBools, 1, (size_t)zip->numFiles); else { - if (read_Bools(a, timeBools, zip->numFiles) < 0) + if (read_Bools(a, timeBools, (size_t)zip->numFiles) < 0) goto failed; } @@ -2916,10 +2919,10 @@ extract_pack_stream(struct archive_read *a, size_t minimum) return (ARCHIVE_FATAL); } if (bytes_avail > (ssize_t)zip->pack_stream_inbytes_remaining) - bytes_avail = zip->pack_stream_inbytes_remaining; + bytes_avail = (ssize_t)zip->pack_stream_inbytes_remaining; zip->pack_stream_inbytes_remaining -= bytes_avail; if (bytes_avail > (ssize_t)zip->folder_outbytes_remaining) - bytes_avail = zip->folder_outbytes_remaining; + bytes_avail = (ssize_t)zip->folder_outbytes_remaining; zip->folder_outbytes_remaining -= bytes_avail; zip->uncompressed_buffer_bytes_remaining = bytes_avail; return (ARCHIVE_OK); @@ -3006,7 +3009,7 @@ extract_pack_stream(struct archive_read *a, size_t minimum) - zip->uncompressed_buffer_bytes_remaining; bytes_in = bytes_avail; if (bytes_in > zip->pack_stream_inbytes_remaining) - bytes_in = zip->pack_stream_inbytes_remaining; + bytes_in = (size_t)zip->pack_stream_inbytes_remaining; /* Drive decompression. */ r = decompress(a, zip, buff_out, &bytes_out, buff_in, &bytes_in); @@ -3022,7 +3025,7 @@ extract_pack_stream(struct archive_read *a, size_t minimum) } zip->pack_stream_inbytes_remaining -= bytes_in; if (bytes_out > zip->folder_outbytes_remaining) - bytes_out = zip->folder_outbytes_remaining; + bytes_out = (size_t)zip->folder_outbytes_remaining; zip->folder_outbytes_remaining -= bytes_out; zip->uncompressed_buffer_bytes_remaining += bytes_out; zip->pack_stream_bytes_unconsumed = bytes_in; @@ -3179,7 +3182,8 @@ read_stream(struct archive_read *a, const void **buff, size_t size, return (ARCHIVE_FATAL); } } - skipped = get_uncompressed_data(a, buff, skip_bytes, 0); + skipped = get_uncompressed_data( + a, buff, (size_t)skip_bytes, 0); if (skipped < 0) return (skipped); skip_bytes -= skipped; @@ -3311,13 +3315,13 @@ setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, } coder2 = &(fc[3]); zip->main_stream_bytes_remaining = - folder->unPackSize[2]; + (size_t)folder->unPackSize[2]; } else if (coder2 != NULL && coder2->codec == _7Z_X86_BCJ2 && zip->pack_stream_remaining == 4 && folder->numInStreams == 5 && folder->numOutStreams == 2) { /* Source type 0 made by 7z */ zip->main_stream_bytes_remaining = - folder->unPackSize[0]; + (size_t)folder->unPackSize[0]; } else { /* We got an unexpected form. */ archive_set_error(&(a->archive), @@ -3330,7 +3334,7 @@ setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, if ((r = seek_pack(a)) < 0) return (r); zip->pack_stream_bytes_unconsumed = - zip->pack_stream_inbytes_remaining; + (size_t)zip->pack_stream_inbytes_remaining; read_consume(a); /* Read following three sub streams. */ @@ -3352,7 +3356,7 @@ setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, /* Allocate memory for the decorded data of a sub * stream. */ - b[i] = malloc(zip->folder_outbytes_remaining); + b[i] = malloc((size_t)zip->folder_outbytes_remaining); if (b[i] == NULL) { archive_set_error(&a->archive, ENOMEM, "No memory for 7-Zip decompression"); @@ -3447,7 +3451,7 @@ skip_stream(struct archive_read *a, size_t skip_bytes) "Truncated 7-Zip file body"); return (ARCHIVE_FATAL); } - bytes -= skipped_bytes; + bytes -= (size_t)skipped_bytes; if (zip->pack_stream_bytes_unconsumed) read_consume(a); } diff --git a/libarchive/archive_read_support_format_cab.c b/libarchive/archive_read_support_format_cab.c index 0bc7c999c..d822acecb 100644 --- a/libarchive/archive_read_support_format_cab.c +++ b/libarchive/archive_read_support_format_cab.c @@ -798,7 +798,7 @@ cab_read_header(struct archive_read *a) file->offset = archive_le32dec(p + CFFILE_uoffFolderStart); file->folder = archive_le16dec(p + CFFILE_iFolder); file->mtime = cab_dos_time(p + CFFILE_date_time); - file->attr = archive_le16dec(p + CFFILE_attribs); + file->attr = (uint8_t)archive_le16dec(p + CFFILE_attribs); __archive_read_consume(a, 16); cab->cab_offset += 16; @@ -1028,7 +1028,7 @@ archive_read_format_cab_read_data(struct archive_read *a, } if (cab->entry_unconsumed) { /* Consume as much as the compressor actually used. */ - r = cab_consume_cfdata(a, cab->entry_unconsumed); + r = (int)cab_consume_cfdata(a, cab->entry_unconsumed); cab->entry_unconsumed = 0; if (r < 0) return (r); @@ -1367,7 +1367,8 @@ cab_read_ahead_cfdata_none(struct archive_read *a, ssize_t *avail) /* we've already skipped some bytes before really read. */ skipped_bytes = cfdata->read_offset; cfdata->read_offset = 0; - cfdata->uncompressed_bytes_remaining += skipped_bytes; + cfdata->uncompressed_bytes_remaining += + (uint16_t)skipped_bytes; } else skipped_bytes = 0; do { @@ -1543,7 +1544,7 @@ cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail) return (NULL); } } - uavail = cab->stream.total_out; + uavail = (uint16_t)cab->stream.total_out; if (uavail < cfdata->uncompressed_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, @@ -1721,7 +1722,7 @@ cab_read_ahead_cfdata_lzx(struct archive_read *a, ssize_t *avail) } } - uavail = cab->xstrm.total_out; + uavail = (uint16_t)cab->xstrm.total_out; /* * Make sure a read pointer advances to next CFDATA. */ @@ -1821,8 +1822,8 @@ cab_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) } continue; } - cfdata->read_offset += cbytes; - cfdata->uncompressed_bytes_remaining -= cbytes; + cfdata->read_offset += (uint16_t)cbytes; + cfdata->uncompressed_bytes_remaining -= (uint16_t)cbytes; break; } else if (cbytes == 0) { err = cab_next_cfdata(a); @@ -1846,7 +1847,7 @@ cab_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) if (avail <= 0) return (ARCHIVE_FATAL); if (avail > cbytes) - avail = cbytes; + avail = (ssize_t)cbytes; if (cab_minimum_consume_cfdata(a, avail) < 0) return (ARCHIVE_FATAL); cbytes -= avail; @@ -1875,8 +1876,8 @@ cab_minimum_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) else cbytes = cfdata->unconsumed; rbytes -= cbytes; - cfdata->read_offset += cbytes; - cfdata->uncompressed_bytes_remaining -= cbytes; + cfdata->read_offset += (uint16_t)cbytes; + cfdata->uncompressed_bytes_remaining -= (uint16_t)cbytes; cfdata->unconsumed -= cbytes; } else { cbytes = cfdata->uncompressed_avail - cfdata->read_offset; @@ -1884,8 +1885,8 @@ cab_minimum_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) if (consumed_bytes < cbytes) cbytes = consumed_bytes; rbytes -= cbytes; - cfdata->read_offset += cbytes; - cfdata->uncompressed_bytes_remaining -= cbytes; + cfdata->read_offset += (uint16_t)cbytes; + cfdata->uncompressed_bytes_remaining -= (uint16_t)cbytes; } if (cfdata->unconsumed) { @@ -1896,12 +1897,12 @@ cab_minimum_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) } if (cbytes) { /* Compute the sum. */ - cab_checksum_update(a, cbytes); + cab_checksum_update(a, (size_t)cbytes); /* Consume as much as the compressor actually used. */ __archive_read_consume(a, cbytes); cab->cab_offset += cbytes; - cfdata->compressed_bytes_remaining -= cbytes; + cfdata->compressed_bytes_remaining -= (uint16_t)cbytes; if (cfdata->compressed_bytes_remaining == 0) { err = cab_checksum_finish(a); if (err < 0) @@ -1945,7 +1946,7 @@ cab_read_data(struct archive_read *a, const void **buff, return (bytes_avail); } if (bytes_avail > cab->entry_bytes_remaining) - bytes_avail = cab->entry_bytes_remaining; + bytes_avail = (ssize_t)cab->entry_bytes_remaining; *size = bytes_avail; *offset = cab->entry_offset; @@ -1971,7 +1972,7 @@ archive_read_format_cab_read_data_skip(struct archive_read *a) if (cab->entry_unconsumed) { /* Consume as much as the compressor actually used. */ - r = cab_consume_cfdata(a, cab->entry_unconsumed); + r = (int)cab_consume_cfdata(a, cab->entry_unconsumed); cab->entry_unconsumed = 0; if (r < 0) return (r); diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index a1f842a30..ff29e1ffd 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -398,11 +398,12 @@ archive_read_format_cpio_read_header(struct archive_read *a, /* If this is a symlink, read the link contents. */ if (archive_entry_filetype(entry) == AE_IFLNK) { - h = __archive_read_ahead(a, cpio->entry_bytes_remaining, NULL); + h = __archive_read_ahead(a, + (size_t)cpio->entry_bytes_remaining, NULL); if (h == NULL) return (ARCHIVE_FATAL); if (archive_entry_copy_symlink_l(entry, (const char *)h, - cpio->entry_bytes_remaining, sconv) != 0) { + (size_t)cpio->entry_bytes_remaining, sconv) != 0) { if (errno == ENOMEM) { archive_set_error(&a->archive, ENOMEM, "Can't allocate memory for Linkname"); @@ -458,7 +459,7 @@ archive_read_format_cpio_read_data(struct archive_read *a, if (bytes_read <= 0) return (ARCHIVE_FATAL); if (bytes_read > cpio->entry_bytes_remaining) - bytes_read = cpio->entry_bytes_remaining; + bytes_read = (ssize_t)cpio->entry_bytes_remaining; *size = bytes_read; cpio->entry_bytes_unconsumed = bytes_read; *offset = cpio->entry_offset; @@ -603,17 +604,23 @@ header_newc(struct archive_read *a, struct cpio *cpio, /* TODO: Abort here? */ } - archive_entry_set_devmajor(entry, atol16(header + newc_devmajor_offset, newc_devmajor_size)); - archive_entry_set_devminor(entry, atol16(header + newc_devminor_offset, newc_devminor_size)); + archive_entry_set_devmajor(entry, + (dev_t)atol16(header + newc_devmajor_offset, newc_devmajor_size)); + archive_entry_set_devminor(entry, + (dev_t)atol16(header + newc_devminor_offset, newc_devminor_size)); archive_entry_set_ino(entry, atol16(header + newc_ino_offset, newc_ino_size)); - archive_entry_set_mode(entry, atol16(header + newc_mode_offset, newc_mode_size)); + archive_entry_set_mode(entry, + (mode_t)atol16(header + newc_mode_offset, newc_mode_size)); archive_entry_set_uid(entry, atol16(header + newc_uid_offset, newc_uid_size)); archive_entry_set_gid(entry, atol16(header + newc_gid_offset, newc_gid_size)); - archive_entry_set_nlink(entry, atol16(header + newc_nlink_offset, newc_nlink_size)); - archive_entry_set_rdevmajor(entry, atol16(header + newc_rdevmajor_offset, newc_rdevmajor_size)); - archive_entry_set_rdevminor(entry, atol16(header + newc_rdevminor_offset, newc_rdevminor_size)); + archive_entry_set_nlink(entry, + (unsigned int)atol16(header + newc_nlink_offset, newc_nlink_size)); + archive_entry_set_rdevmajor(entry, + (dev_t)atol16(header + newc_rdevmajor_offset, newc_rdevmajor_size)); + archive_entry_set_rdevminor(entry, + (dev_t)atol16(header + newc_rdevminor_offset, newc_rdevminor_size)); archive_entry_set_mtime(entry, atol16(header + newc_mtime_offset, newc_mtime_size), 0); - *namelength = atol16(header + newc_namesize_offset, newc_namesize_size); + *namelength = (size_t)atol16(header + newc_namesize_offset, newc_namesize_size); /* Pad name to 2 more than a multiple of 4. */ *name_pad = (2 - *namelength) & 3; @@ -767,15 +774,19 @@ header_odc(struct archive_read *a, struct cpio *cpio, /* Parse out octal fields. */ header = (const char *)h; - archive_entry_set_dev(entry, atol8(header + odc_dev_offset, odc_dev_size)); + archive_entry_set_dev(entry, + (dev_t)atol8(header + odc_dev_offset, odc_dev_size)); archive_entry_set_ino(entry, atol8(header + odc_ino_offset, odc_ino_size)); - archive_entry_set_mode(entry, atol8(header + odc_mode_offset, odc_mode_size)); + archive_entry_set_mode(entry, + (mode_t)atol8(header + odc_mode_offset, odc_mode_size)); archive_entry_set_uid(entry, atol8(header + odc_uid_offset, odc_uid_size)); archive_entry_set_gid(entry, atol8(header + odc_gid_offset, odc_gid_size)); - archive_entry_set_nlink(entry, atol8(header + odc_nlink_offset, odc_nlink_size)); - archive_entry_set_rdev(entry, atol8(header + odc_rdev_offset, odc_rdev_size)); + archive_entry_set_nlink(entry, + (unsigned int)atol8(header + odc_nlink_offset, odc_nlink_size)); + archive_entry_set_rdev(entry, + (dev_t)atol8(header + odc_rdev_offset, odc_rdev_size)); archive_entry_set_mtime(entry, atol8(header + odc_mtime_offset, odc_mtime_size), 0); - *namelength = atol8(header + odc_namesize_offset, odc_namesize_size); + *namelength = (size_t)atol8(header + odc_namesize_offset, odc_namesize_size); *name_pad = 0; /* No padding of filename. */ /* @@ -816,15 +827,19 @@ header_afiol(struct archive_read *a, struct cpio *cpio, /* Parse out octal fields. */ header = (const char *)h; - archive_entry_set_dev(entry, atol16(header + afiol_dev_offset, afiol_dev_size)); + archive_entry_set_dev(entry, + (dev_t)atol16(header + afiol_dev_offset, afiol_dev_size)); archive_entry_set_ino(entry, atol16(header + afiol_ino_offset, afiol_ino_size)); - archive_entry_set_mode(entry, atol8(header + afiol_mode_offset, afiol_mode_size)); + archive_entry_set_mode(entry, + (mode_t)atol8(header + afiol_mode_offset, afiol_mode_size)); archive_entry_set_uid(entry, atol16(header + afiol_uid_offset, afiol_uid_size)); archive_entry_set_gid(entry, atol16(header + afiol_gid_offset, afiol_gid_size)); - archive_entry_set_nlink(entry, atol16(header + afiol_nlink_offset, afiol_nlink_size)); - archive_entry_set_rdev(entry, atol16(header + afiol_rdev_offset, afiol_rdev_size)); + archive_entry_set_nlink(entry, + (unsigned int)atol16(header + afiol_nlink_offset, afiol_nlink_size)); + archive_entry_set_rdev(entry, + (dev_t)atol16(header + afiol_rdev_offset, afiol_rdev_size)); archive_entry_set_mtime(entry, atol16(header + afiol_mtime_offset, afiol_mtime_size), 0); - *namelength = atol16(header + afiol_namesize_offset, afiol_namesize_size); + *namelength = (size_t)atol16(header + afiol_namesize_offset, afiol_namesize_size); *name_pad = 0; /* No padding of filename. */ cpio->entry_bytes_remaining = diff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c index 364afdf2b..71b03d2c8 100644 --- a/libarchive/archive_read_support_format_iso9660.c +++ b/libarchive/archive_read_support_format_iso9660.c @@ -975,8 +975,8 @@ read_children(struct archive_read *a, struct file_info *parent) iso9660->current_position = parent->offset; } - step = ((parent->size + iso9660->logical_block_size -1) / - iso9660->logical_block_size) * iso9660->logical_block_size; + step = (size_t)(((parent->size + iso9660->logical_block_size -1) / + iso9660->logical_block_size) * iso9660->logical_block_size); b = __archive_read_ahead(a, step, NULL); if (b == NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, @@ -1397,7 +1397,7 @@ zisofs_read_data(struct archive_read *a, return (ARCHIVE_FATAL); } if (bytes_read > iso9660->entry_bytes_remaining) - bytes_read = iso9660->entry_bytes_remaining; + bytes_read = (ssize_t)iso9660->entry_bytes_remaining; avail = bytes_read; uncompressed_size = 0; @@ -1405,9 +1405,9 @@ zisofs_read_data(struct archive_read *a, size_t ceil, xsize; /* Allocate block pointers buffer. */ - ceil = (zisofs->pz_uncompressed_size + + ceil = (size_t)((zisofs->pz_uncompressed_size + (((int64_t)1) << zisofs->pz_log2_bs) - 1) - >> zisofs->pz_log2_bs; + >> zisofs->pz_log2_bs); xsize = (ceil + 1) * 4; if (zisofs->block_pointers_alloc < xsize) { size_t alloc; @@ -1671,7 +1671,7 @@ archive_read_format_iso9660_read_data(struct archive_read *a, if (*buff == NULL) return (ARCHIVE_FATAL); if (bytes_read > iso9660->entry_bytes_remaining) - bytes_read = iso9660->entry_bytes_remaining; + bytes_read = (ssize_t)iso9660->entry_bytes_remaining; *size = bytes_read; *offset = iso9660->entry_sparse_offset; iso9660->entry_sparse_offset += bytes_read; diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index ace3b3a9c..a92b072ab 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -951,7 +951,7 @@ lha_read_file_header_1(struct archive_read *a, struct lha *lha) /* Read extended headers */ err2 = lha_read_file_extended_header(a, lha, NULL, 2, - lha->compsize + 2, &extdsize); + (size_t)(lha->compsize + 2), &extdsize); if (err2 < ARCHIVE_WARN) return (err2); if (err2 < err) @@ -1446,7 +1446,7 @@ lha_read_data_none(struct archive_read *a, const void **buff, return (ARCHIVE_FATAL); } if (bytes_avail > lha->entry_bytes_remaining) - bytes_avail = lha->entry_bytes_remaining; + bytes_avail = (ssize_t)lha->entry_bytes_remaining; lha->entry_crc_calculated = lha_crc16(lha->entry_crc_calculated, *buff, bytes_avail); *size = bytes_avail; @@ -1529,7 +1529,7 @@ lha_read_data_lzh(struct archive_read *a, const void **buff, return (ARCHIVE_FATAL); } if (bytes_avail > lha->entry_bytes_remaining) - bytes_avail = lha->entry_bytes_remaining; + bytes_avail = (ssize_t)lha->entry_bytes_remaining; lha->strm.avail_in = bytes_avail; lha->strm.total_in = 0; @@ -1575,7 +1575,7 @@ static int archive_read_format_lha_read_data_skip(struct archive_read *a) { struct lha *lha; - off_t bytes_skipped; + int64_t bytes_skipped; lha = (struct lha *)(a->format->data); @@ -2016,7 +2016,7 @@ lzh_copy_from_window(struct lzh_stream *strm, struct lzh_dec *ds) if (ds->w_pos - ds->copy_pos <= strm->avail_out) copy_bytes = ds->w_pos - ds->copy_pos; else - copy_bytes = strm->avail_out; + copy_bytes = (size_t)strm->avail_out; memcpy(strm->next_out, ds->w_buff + ds->copy_pos, copy_bytes); ds->copy_pos += copy_bytes; @@ -2024,7 +2024,7 @@ lzh_copy_from_window(struct lzh_stream *strm, struct lzh_dec *ds) if (ds->w_remaining <= strm->avail_out) copy_bytes = ds->w_remaining; else - copy_bytes = strm->avail_out; + copy_bytes = (size_t)strm->avail_out; memcpy(strm->next_out, ds->w_buff + ds->w_size - ds->w_remaining, copy_bytes); ds->w_remaining -= copy_bytes; diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 5c307ef20..6fb576291 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -1183,7 +1183,7 @@ parse_device(struct archive *a, struct archive_entry *entry, char *val) comma1 = strchr(val, ','); if (comma1 == NULL) { - archive_entry_set_dev(entry, mtree_atol10(&val)); + archive_entry_set_dev(entry, (dev_t)mtree_atol10(&val)); return (ARCHIVE_OK); } ++comma1; @@ -1194,8 +1194,8 @@ parse_device(struct archive *a, struct archive_entry *entry, char *val) return (ARCHIVE_WARN); } ++comma2; - archive_entry_set_rdevmajor(entry, mtree_atol(&comma1)); - archive_entry_set_rdevminor(entry, mtree_atol(&comma2)); + archive_entry_set_rdevmajor(entry, (dev_t)mtree_atol(&comma1)); + archive_entry_set_rdevminor(entry, (dev_t)mtree_atol(&comma2)); return (ARCHIVE_OK); } @@ -1280,7 +1280,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, if (val[0] >= '0' && val[0] <= '9') { *parsed_kws |= MTREE_HAS_PERM; archive_entry_set_perm(entry, - mtree_atol8(&val)); + (mode_t)mtree_atol8(&val)); } else { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -1292,7 +1292,8 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, case 'n': if (strcmp(key, "nlink") == 0) { *parsed_kws |= MTREE_HAS_NLINK; - archive_entry_set_nlink(entry, mtree_atol10(&val)); + archive_entry_set_nlink(entry, + (unsigned int)mtree_atol10(&val)); break; } case 'r': @@ -1434,7 +1435,7 @@ read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offs *buff = mtree->buff; *offset = mtree->offset; if ((int64_t)mtree->buffsize > mtree->cur_size - mtree->offset) - bytes_to_read = mtree->cur_size - mtree->offset; + bytes_to_read = (size_t)(mtree->cur_size - mtree->offset); else bytes_to_read = mtree->buffsize; bytes_read = read(mtree->fd, mtree->buff, bytes_to_read); diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c index d2a893ec5..9b4a67e9e 100644 --- a/libarchive/archive_read_support_format_rar.c +++ b/libarchive/archive_read_support_format_rar.c @@ -453,7 +453,7 @@ rar_br_fillup(struct archive_read *a, struct rar_br *br) if (br->next_in == NULL) return (0); if (br->avail_in > rar->bytes_remaining) - br->avail_in = rar->bytes_remaining; + br->avail_in = (ssize_t)rar->bytes_remaining; if (br->avail_in == 0) return (0); } @@ -481,7 +481,7 @@ rar_br_preparation(struct archive_read *a, struct rar_br *br) return (ARCHIVE_FATAL); } if (br->avail_in > rar->bytes_remaining) - br->avail_in = rar->bytes_remaining; + br->avail_in = (ssize_t)rar->bytes_remaining; if (br->cache_avail == 0) (void)rar_br_fillup(a, br); } @@ -522,7 +522,7 @@ lzss_size(struct lzss *lzss) static inline int lzss_offset_for_position(struct lzss *lzss, int64_t pos) { - return pos & lzss->mask; + return (int)(pos & lzss->mask); } static inline unsigned char * @@ -1084,11 +1084,11 @@ read_header(struct archive_read *a, struct archive_entry *entry, return (ARCHIVE_FATAL); } - if ((h = __archive_read_ahead(a, header_size - 7, NULL)) == NULL) + if ((h = __archive_read_ahead(a, (size_t)header_size - 7, NULL)) == NULL) return (ARCHIVE_FATAL); /* File Header CRC check. */ - crc32_val = crc32(crc32_val, h, header_size - 7); + crc32_val = crc32(crc32_val, h, (unsigned)(header_size - 7)); if ((crc32_val & 0xffff) != archive_le16dec(rar_header.crc)) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); @@ -1148,7 +1148,7 @@ read_header(struct archive_read *a, struct archive_entry *entry, size_t distance = p - (const char *)h; header_size += rar->packed_size; /* Make sure we have the extended data. */ - if ((h = __archive_read_ahead(a, header_size - 7, NULL)) == NULL) + if ((h = __archive_read_ahead(a, (size_t)header_size - 7, NULL)) == NULL) return (ARCHIVE_FATAL); p = h; endp = p + header_size - 7; @@ -1322,7 +1322,8 @@ read_header(struct archive_read *a, struct archive_entry *entry, rar->bytes_remaining = rar->packed_size; rar->bytes_uncopied = rar->bytes_unconsumed = 0; - rar->lzss.position = rar->dictionary_size = rar->offset = 0; + rar->lzss.position = rar->offset = 0; + rar->dictionary_size = 0; rar->offset_outgoing = 0; rar->br.cache_avail = 0; rar->br.avail_in = 0; @@ -1477,11 +1478,12 @@ read_symlink_stored(struct archive_read *a, struct archive_entry *entry, int ret = (ARCHIVE_OK); rar = (struct rar *)(a->format->data); - if ((h = __archive_read_ahead(a, rar->packed_size, NULL)) == NULL) + if ((h = __archive_read_ahead(a, (size_t)rar->packed_size, NULL)) == NULL) return (ARCHIVE_FATAL); p = h; - if (archive_entry_copy_symlink_l(entry, p, rar->packed_size, sconv)) + if (archive_entry_copy_symlink_l(entry, + p, (size_t)rar->packed_size, sconv)) { if (errno == ENOMEM) { @@ -1528,7 +1530,7 @@ read_data_stored(struct archive_read *a, const void **buff, size_t *size, return (ARCHIVE_FATAL); } if (bytes_avail > rar->bytes_remaining) - bytes_avail = rar->bytes_remaining; + bytes_avail = (ssize_t)rar->bytes_remaining; *size = bytes_avail; *offset = rar->offset; @@ -1587,7 +1589,7 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset)) bs = rar->unp_buffer_size - rar->unp_offset; else - bs = rar->bytes_uncopied; + bs = (size_t)rar->bytes_uncopied; ret = copy_from_lzss_window(a, buff, rar->offset, bs); if (ret != ARCHIVE_OK) return (ret); @@ -1715,7 +1717,7 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset)) bs = rar->unp_buffer_size - rar->unp_offset; else - bs = rar->bytes_uncopied; + bs = (size_t)rar->bytes_uncopied; ret = copy_from_lzss_window(a, buff, rar->offset, bs); if (ret != ARCHIVE_OK) return (ret); @@ -1978,7 +1980,7 @@ parse_codes(struct archive_read *a) if (rar->unp_size >= DICTIONARY_MAX_SIZE) rar->dictionary_size = DICTIONARY_MAX_SIZE; else - rar->dictionary_size = rar_fls(rar->unp_size) << 1; + rar->dictionary_size = rar_fls((unsigned int)rar->unp_size) << 1; rar->lzss.window = (unsigned char *)realloc(rar->lzss.window, rar->dictionary_size); if (rar->lzss.window == NULL) { diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c index 52d431e7e..39f86be06 100644 --- a/libarchive/archive_read_support_format_tar.c +++ b/libarchive/archive_read_support_format_tar.c @@ -561,11 +561,11 @@ skip_hole: return (ARCHIVE_FATAL); } if (bytes_read > tar->entry_bytes_remaining) - bytes_read = tar->entry_bytes_remaining; + bytes_read = (ssize_t)tar->entry_bytes_remaining; /* Don't read more than is available in the * current sparse block. */ if (tar->sparse_list->remaining < bytes_read) - bytes_read = tar->sparse_list->remaining; + bytes_read = (ssize_t)tar->sparse_list->remaining; *size = bytes_read; *offset = tar->sparse_list->offset; tar->sparse_list->remaining -= bytes_read; @@ -786,7 +786,7 @@ checksum(struct archive_read *a, const void *h) * Test the checksum. Note that POSIX specifies _unsigned_ * bytes for this calculation. */ - sum = tar_atol(header->checksum, sizeof(header->checksum)); + sum = (int)tar_atol(header->checksum, sizeof(header->checksum)); check = 0; for (i = 0; i < 148; i++) check += (unsigned char)bytes[i]; @@ -847,7 +847,7 @@ header_Solaris_ACL(struct archive_read *a, struct tar *tar, * more to make sure that we don't overrun acl_text later. */ header = (const struct archive_entry_header_ustar *)h; - size = tar_atol(header->size, sizeof(header->size)); + size = (size_t)tar_atol(header->size, sizeof(header->size)); err = read_body_to_string(a, tar, &(tar->acl_text), h, unconsumed); if (err != ARCHIVE_OK) return (err); @@ -1021,7 +1021,7 @@ read_body_to_string(struct archive_read *a, struct tar *tar, } /* Fail if we can't make our buffer big enough. */ - if (archive_string_ensure(as, size+1) == NULL) { + if (archive_string_ensure(as, (size_t)size+1) == NULL) { archive_set_error(&a->archive, ENOMEM, "No memory"); return (ARCHIVE_FATAL); @@ -1030,15 +1030,15 @@ read_body_to_string(struct archive_read *a, struct tar *tar, tar_flush_unconsumed(a, unconsumed); /* Read the body into the string. */ - *unconsumed = (size + 511) & ~ 511; + *unconsumed = (size_t)((size + 511) & ~ 511); src = __archive_read_ahead(a, *unconsumed, NULL); if (src == NULL) { *unconsumed = 0; return (ARCHIVE_FATAL); } - memcpy(as->s, src, size); + memcpy(as->s, src, (size_t)size); as->s[size] = '\0'; - as->length = size; + as->length = (size_t)size; return (ARCHIVE_OK); } @@ -1068,7 +1068,8 @@ header_common(struct archive_read *a, struct tar *tar, archive_string_empty(&(tar->entry_linkpath)); /* Parse out the numeric fields (all are octal) */ - archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode))); + archive_entry_set_mode(entry, + (mode_t)tar_atol(header->mode, sizeof(header->mode))); archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid))); archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid))); tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size)); @@ -1310,13 +1311,13 @@ read_mac_metadata_blob(struct archive_read *a, struct tar *tar, * Q: Is the above idea really possible? Even * when there are GNU or pax extension entries? */ - data = __archive_read_ahead(a, size, NULL); + data = __archive_read_ahead(a, (size_t)size, NULL); if (data == NULL) { *unconsumed = 0; return (ARCHIVE_FATAL); } - archive_entry_copy_mac_metadata(entry, data, size); - *unconsumed = (size + 511) & ~ 511; + archive_entry_copy_mac_metadata(entry, data, (size_t)size); + *unconsumed = (size_t)((size + 511) & ~ 511); tar_flush_unconsumed(a, unconsumed); return (tar_read_header(a, tar, entry, unconsumed)); } @@ -1424,9 +1425,9 @@ header_ustar(struct archive_read *a, struct tar *tar, /* Parse out device numbers only for char and block specials. */ if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { - archive_entry_set_rdevmajor(entry, + archive_entry_set_rdevmajor(entry, (dev_t) tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); - archive_entry_set_rdevminor(entry, + archive_entry_set_rdevminor(entry, (dev_t) tar_atol(header->rdevminor, sizeof(header->rdevminor))); } @@ -1709,11 +1710,11 @@ pax_attribute(struct archive_read *a, struct tar *tar, /* GNU "1.0" sparse pax format */ if (strcmp(key, "GNU.sparse.major") == 0) { - tar->sparse_gnu_major = tar_atol10(value, strlen(value)); + tar->sparse_gnu_major = (int)tar_atol10(value, strlen(value)); tar->sparse_gnu_pending = 1; } if (strcmp(key, "GNU.sparse.minor") == 0) { - tar->sparse_gnu_minor = tar_atol10(value, strlen(value)); + tar->sparse_gnu_minor = (int)tar_atol10(value, strlen(value)); tar->sparse_gnu_pending = 1; } if (strcmp(key, "GNU.sparse.name") == 0) { @@ -1796,20 +1797,20 @@ pax_attribute(struct archive_read *a, struct tar *tar, } } else if (strcmp(key, "SCHILY.devmajor") == 0) { archive_entry_set_rdevmajor(entry, - tar_atol10(value, strlen(value))); + (dev_t)tar_atol10(value, strlen(value))); } else if (strcmp(key, "SCHILY.devminor") == 0) { archive_entry_set_rdevminor(entry, - tar_atol10(value, strlen(value))); + (dev_t)tar_atol10(value, strlen(value))); } else if (strcmp(key, "SCHILY.fflags") == 0) { archive_entry_copy_fflags_text(entry, value); } else if (strcmp(key, "SCHILY.dev") == 0) { archive_entry_set_dev(entry, - tar_atol10(value, strlen(value))); + (dev_t)tar_atol10(value, strlen(value))); } else if (strcmp(key, "SCHILY.ino") == 0) { archive_entry_set_ino(entry, tar_atol10(value, strlen(value))); } else if (strcmp(key, "SCHILY.nlink") == 0) { - archive_entry_set_nlink(entry, + archive_entry_set_nlink(entry, (unsigned) tar_atol10(value, strlen(value))); } else if (strcmp(key, "SCHILY.realsize") == 0) { tar->realsize = tar_atol10(value, strlen(value)); @@ -2018,9 +2019,9 @@ header_gnutar(struct archive_read *a, struct tar *tar, /* Parse out device numbers only for char and block specials */ if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { - archive_entry_set_rdevmajor(entry, + archive_entry_set_rdevmajor(entry, (dev_t) tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); - archive_entry_set_rdevminor(entry, + archive_entry_set_rdevminor(entry, (dev_t) tar_atol(header->rdevminor, sizeof(header->rdevminor))); } else archive_entry_set_rdev(entry, 0); @@ -2255,7 +2256,8 @@ gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, * don't require this, but they should. */ do { - bytes_read = readline(a, tar, &p, tar_min(*remaining, 100), unconsumed); + bytes_read = readline(a, tar, &p, + (ssize_t)tar_min(*remaining, 100), unconsumed); if (bytes_read <= 0) return (ARCHIVE_FATAL); *remaining -= bytes_read; @@ -2296,7 +2298,7 @@ gnu_sparse_10_read(struct archive_read *a, struct tar *tar, size_t *unconsumed) remaining = tar->entry_bytes_remaining; /* Parse entries. */ - entries = gnu_sparse_10_atol(a, tar, &remaining, unconsumed); + entries = (int)gnu_sparse_10_atol(a, tar, &remaining, unconsumed); if (entries < 0) return (ARCHIVE_FATAL); /* Parse the individual entries. */ @@ -2314,11 +2316,11 @@ gnu_sparse_10_read(struct archive_read *a, struct tar *tar, size_t *unconsumed) } /* Skip rest of block... */ tar_flush_unconsumed(a, unconsumed); - bytes_read = tar->entry_bytes_remaining - remaining; + bytes_read = (ssize_t)(tar->entry_bytes_remaining - remaining); to_skip = 0x1ff & -bytes_read; if (to_skip != __archive_read_consume(a, to_skip)) return (ARCHIVE_FATAL); - return (bytes_read + to_skip); + return ((ssize_t)(bytes_read + to_skip)); } /* diff --git a/libarchive/archive_read_support_format_xar.c b/libarchive/archive_read_support_format_xar.c index 92569bb64..3565c22e6 100644 --- a/libarchive/archive_read_support_format_xar.c +++ b/libarchive/archive_read_support_format_xar.c @@ -183,9 +183,9 @@ struct xar_file { time_t mtime; time_t atime; struct archive_string uname; - uid_t uid; + int64_t uid; struct archive_string gname; - gid_t gid; + int64_t gid; mode_t mode; dev_t dev; dev_t devmajor; @@ -602,7 +602,8 @@ read_toc(struct archive_read *a) r = move_reading_point(a, xar->toc_chksum_offset); if (r != ARCHIVE_OK) return (r); - b = __archive_read_ahead(a, xar->toc_chksum_size, &bytes); + b = __archive_read_ahead(a, + (size_t)xar->toc_chksum_size, &bytes); if (bytes < 0) return ((int)bytes); if ((uint64_t)bytes < xar->toc_chksum_size) { @@ -611,7 +612,8 @@ read_toc(struct archive_read *a) "Truncated archive file"); return (ARCHIVE_FATAL); } - r = checksum_final(a, b, xar->toc_chksum_size, NULL, 0); + r = checksum_final(a, b, + (size_t)xar->toc_chksum_size, NULL, 0); __archive_read_consume(a, xar->toc_chksum_size); xar->offset += xar->toc_chksum_size; if (r != ARCHIVE_OK) @@ -2065,7 +2067,7 @@ xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list) xar->file->hdnext = xar->hdlink_orgs; xar->hdlink_orgs = xar->file; } else { - xar->file->link = atol10(attr->value, + xar->file->link = (unsigned)atol10(attr->value, strlen(attr->value)); if (xar->file->link > 0) if (add_link(a, xar, xar->file) != ARCHIVE_OK) { @@ -2761,7 +2763,7 @@ xml_data(void *userData, const char *s, int len) xar->file->has |= HAS_MODE; xar->file->mode = (xar->file->mode & AE_IFMT) | - (atol8(s, len) & ~AE_IFMT); + ((mode_t)(atol8(s, len)) & ~AE_IFMT); break; case FILE_GROUP: xar->file->has |= HAS_GID; diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c index ca3027b07..9e7f9a9a0 100644 --- a/libarchive/archive_read_support_format_zip.c +++ b/libarchive/archive_read_support_format_zip.c @@ -328,7 +328,7 @@ slurp_central_directory(struct archive_read *a, struct zip *zip) zip_entry->system = p[5]; /* version_required = archive_le16dec(p + 6); */ zip_entry->flags = archive_le16dec(p + 8); - zip_entry->compression = archive_le16dec(p + 10); + zip_entry->compression = (char)archive_le16dec(p + 10); zip_entry->mtime = zip_time(p + 12); zip_entry->crc32 = archive_le32dec(p + 16); zip_entry->compressed_size = archive_le32dec(p + 20); @@ -420,7 +420,7 @@ archive_read_format_zip_seekable_read_header(struct archive_read *a, if ((zip->entry->mode & AE_IFMT) == AE_IFLNK) { const void *p; struct archive_string_conv *sconv; - size_t linkname_length = archive_entry_size(entry); + size_t linkname_length = (size_t)archive_entry_size(entry); archive_entry_set_size(entry, 0); p = __archive_read_ahead(a, linkname_length, NULL); @@ -637,7 +637,7 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, version = p[4]; zip_entry->system = p[5]; zip_entry->flags = archive_le16dec(p + 6); - zip_entry->compression = archive_le16dec(p + 8); + zip_entry->compression = (char)archive_le16dec(p + 8); zip_entry->mtime = zip_time(p + 10); local_crc32 = archive_le32dec(p + 14); compressed_size = archive_le32dec(p + 18); @@ -994,7 +994,7 @@ zip_read_data_none(struct archive_read *a, const void **_buff, return (ARCHIVE_FATAL); } if (bytes_avail > zip->entry_bytes_remaining) - bytes_avail = zip->entry_bytes_remaining; + bytes_avail = (ssize_t)zip->entry_bytes_remaining; } *size = bytes_avail; zip->entry_bytes_remaining -= bytes_avail; @@ -1058,7 +1058,7 @@ zip_read_data_deflate(struct archive_read *a, const void **buff, compressed_buff = __archive_read_ahead(a, 1, &bytes_avail); if (0 == (zip->entry->flags & ZIP_LENGTH_AT_END) && bytes_avail > zip->entry_bytes_remaining) { - bytes_avail = zip->entry_bytes_remaining; + bytes_avail = (ssize_t)zip->entry_bytes_remaining; } if (bytes_avail <= 0) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, diff --git a/libarchive/archive_string_sprintf.c b/libarchive/archive_string_sprintf.c index 3b3dd4ed3..964ea2bea 100644 --- a/libarchive/archive_string_sprintf.c +++ b/libarchive/archive_string_sprintf.c @@ -131,7 +131,7 @@ archive_string_vsprintf(struct archive_string *as, const char *fmt, break; case 'c': s = va_arg(ap, int); - archive_strappend_char(as, s); + archive_strappend_char(as, (char)s); break; case 'd': switch(long_flag) { diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index 75ea21726..65bf4d367 100644 --- a/libarchive/archive_windows.c +++ b/libarchive/archive_windows.c @@ -109,7 +109,7 @@ getino(struct ustat *ub) ULARGE_INTEGER ino64; ino64.QuadPart = ub->st_ino; /* I don't know this hashing is correct way */ - return (ino64.LowPart ^ (ino64.LowPart >> INOSIZE)); + return ((ino_t)(ino64.LowPart ^ (ino64.LowPart >> INOSIZE))); } /* @@ -558,7 +558,7 @@ copy_stat(struct stat *st, struct ustat *us) st->st_ino = getino(us); st->st_mode = us->st_mode; st->st_nlink = us->st_nlink; - st->st_size = us->st_size; + st->st_size = (off_t)us->st_size; st->st_uid = us->st_uid; st->st_dev = us->st_dev; st->st_rdev = us->st_rdev; diff --git a/libarchive/archive_windows.h b/libarchive/archive_windows.h index 31288c125..4a08f277a 100644 --- a/libarchive/archive_windows.h +++ b/libarchive/archive_windows.h @@ -71,10 +71,6 @@ #include //#define EFTYPE 7 -#if defined(_MSC_VER) -/* TODO: Fix the code, don't suppress the warnings. */ -#pragma warning(disable:4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */ -#endif #if defined(__BORLANDC__) #pragma warn -8068 /* Constant out of range in comparison. */ #pragma warn -8072 /* Suspicious pointer arithmetic. */ diff --git a/libarchive/archive_write.c b/libarchive/archive_write.c index 261a3bf09..6fc3907f3 100644 --- a/libarchive/archive_write.c +++ b/libarchive/archive_write.c @@ -623,7 +623,7 @@ _archive_write_header(struct archive *_a, struct archive_entry *entry) if (a->skip_file_set && archive_entry_dev_is_set(entry) && archive_entry_ino_is_set(entry) && - archive_entry_dev(entry) == a->skip_file_dev && + archive_entry_dev(entry) == (dev_t)a->skip_file_dev && archive_entry_ino64(entry) == a->skip_file_ino) { archive_set_error(&a->archive, 0, "Can't add archive to itself"); diff --git a/libarchive/archive_write_add_filter_compress.c b/libarchive/archive_write_add_filter_compress.c index e29eebd9b..84c6db23c 100644 --- a/libarchive/archive_write_add_filter_compress.c +++ b/libarchive/archive_write_add_filter_compress.c @@ -397,11 +397,11 @@ archive_compressor_compress_write(struct archive_write_filter *f, state->checkpoint = state->in_count + CHECK_GAP; if (state->in_count <= 0x007fffff) - ratio = state->in_count * 256 / state->out_count; - else if ((ratio = state->out_count / 256) == 0) + ratio = (int)(state->in_count * 256 / state->out_count); + else if ((ratio = (int)(state->out_count / 256)) == 0) ratio = 0x7fffffff; else - ratio = state->in_count / ratio; + ratio = (int)(state->in_count / ratio); if (ratio > state->compress_ratio) state->compress_ratio = ratio; diff --git a/libarchive/archive_write_add_filter_gzip.c b/libarchive/archive_write_add_filter_gzip.c index e0fd5003d..b1564774f 100644 --- a/libarchive/archive_write_add_filter_gzip.c +++ b/libarchive/archive_write_add_filter_gzip.c @@ -165,10 +165,10 @@ archive_compressor_gzip_open(struct archive_write_filter *f) data->compressed[1] = 0x8b; data->compressed[2] = 0x08; /* "Deflate" compression */ data->compressed[3] = 0; /* No options */ - data->compressed[4] = (t)&0xff; /* Timestamp */ - data->compressed[5] = (t>>8)&0xff; - data->compressed[6] = (t>>16)&0xff; - data->compressed[7] = (t>>24)&0xff; + data->compressed[4] = (uint8_t)(t)&0xff; /* Timestamp */ + data->compressed[5] = (uint8_t)(t>>8)&0xff; + data->compressed[6] = (uint8_t)(t>>16)&0xff; + data->compressed[7] = (uint8_t)(t>>24)&0xff; data->compressed[8] = 0; /* No deflate options */ data->compressed[9] = 3; /* OS=Unix */ data->stream.next_out += 10; @@ -280,14 +280,14 @@ archive_compressor_gzip_close(struct archive_write_filter *f) } if (ret == ARCHIVE_OK) { /* Build and write out 8-byte trailer. */ - trailer[0] = (data->crc)&0xff; - trailer[1] = (data->crc >> 8)&0xff; - trailer[2] = (data->crc >> 16)&0xff; - trailer[3] = (data->crc >> 24)&0xff; - trailer[4] = (data->total_in)&0xff; - trailer[5] = (data->total_in >> 8)&0xff; - trailer[6] = (data->total_in >> 16)&0xff; - trailer[7] = (data->total_in >> 24)&0xff; + trailer[0] = (uint8_t)(data->crc)&0xff; + trailer[1] = (uint8_t)(data->crc >> 8)&0xff; + trailer[2] = (uint8_t)(data->crc >> 16)&0xff; + trailer[3] = (uint8_t)(data->crc >> 24)&0xff; + trailer[4] = (uint8_t)(data->total_in)&0xff; + trailer[5] = (uint8_t)(data->total_in >> 8)&0xff; + trailer[6] = (uint8_t)(data->total_in >> 16)&0xff; + trailer[7] = (uint8_t)(data->total_in >> 24)&0xff; ret = __archive_write_filter(f->next_filter, trailer, 8); } diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 715c418e8..d79b0f685 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -188,8 +188,8 @@ struct archive_write_disk { struct fixup_entry *current_fixup; int64_t user_uid; int skip_file_set; - dev_t skip_file_dev; - ino_t skip_file_ino; + int64_t skip_file_dev; + int64_t skip_file_ino; time_t start_time; int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid); @@ -1143,9 +1143,10 @@ restore_entry(struct archive_write_disk *a) /* If it's our archive, we're done. */ if (a->skip_file_set && - a->st.st_dev == a->skip_file_dev && - a->st.st_ino == a->skip_file_ino) { - archive_set_error(&a->archive, 0, "Refusing to overwrite archive"); + a->st.st_dev == (dev_t)a->skip_file_dev && + a->st.st_ino == (ino_t)a->skip_file_ino) { + archive_set_error(&a->archive, 0, + "Refusing to overwrite archive"); return (ARCHIVE_FAILED); } diff --git a/libarchive/archive_write_disk_set_standard_lookup.c b/libarchive/archive_write_disk_set_standard_lookup.c index 5ee89a79a..6c7411e3b 100644 --- a/libarchive/archive_write_disk_set_standard_lookup.c +++ b/libarchive/archive_write_disk_set_standard_lookup.c @@ -158,7 +158,7 @@ lookup_gid(void *private_data, const char *gname, int64_t gid) #else #error No way to perform gid lookups on this platform #endif - b->id = gid; + b->id = (gid_t)gid; return (gid); } @@ -228,7 +228,7 @@ lookup_uid(void *private_data, const char *uname, int64_t uid) #else #error No way to look up uids on this platform #endif - b->id = uid; + b->id = (uid_t)uid; return (uid); } diff --git a/libarchive/archive_write_disk_windows.c b/libarchive/archive_write_disk_windows.c index 7664960d2..ff561d904 100644 --- a/libarchive/archive_write_disk_windows.c +++ b/libarchive/archive_write_disk_windows.c @@ -137,8 +137,8 @@ struct archive_write_disk { struct fixup_entry *current_fixup; int64_t user_uid; int skip_file_set; - dev_t skip_file_dev; - ino_t skip_file_ino; + int64_t skip_file_dev; + int64_t skip_file_ino; time_t start_time; int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid); @@ -966,7 +966,7 @@ write_data_block(struct archive_write_disk *a, const char *buff, size_t size) * truncate it to the block boundary. */ bytes_to_write = size; if (a->offset + bytes_to_write > block_end) - bytes_to_write = block_end - a->offset; + bytes_to_write = (DWORD)(block_end - a->offset); } memset(&ol, 0, sizeof(ol)); ol.Offset = (DWORD)(a->offset & 0xFFFFFFFF); @@ -989,7 +989,7 @@ write_data_block(struct archive_write_disk *a, const char *buff, size_t size) a->offset += bytes_written; a->fd_offset = a->offset; } - return (start_size - size); + return ((ssize_t)(start_size - size)); } static ssize_t diff --git a/libarchive/archive_write_private.h b/libarchive/archive_write_private.h index 91284cf1b..06a24a8a6 100644 --- a/libarchive/archive_write_private.h +++ b/libarchive/archive_write_private.h @@ -72,7 +72,7 @@ struct archive_write { /* Dev/ino of the archive being written. */ int skip_file_set; - dev_t skip_file_dev; + int64_t skip_file_dev; int64_t skip_file_ino; /* Utility: Pointer to a block of nulls. */ diff --git a/libarchive/archive_write_set_format_7zip.c b/libarchive/archive_write_set_format_7zip.c index 74f3d6feb..251e8ee66 100644 --- a/libarchive/archive_write_set_format_7zip.c +++ b/libarchive/archive_write_set_format_7zip.c @@ -498,7 +498,7 @@ _7z_write_header(struct archive_write *a, struct archive_entry *entry) if (archive_entry_filetype(entry) == AE_IFLNK) { ssize_t bytes; const void *p = (const void *)archive_entry_symlink(entry); - bytes = compress_out(a, p, file->size, ARCHIVE_Z_RUN); + bytes = compress_out(a, p, (size_t)file->size, ARCHIVE_Z_RUN); if (bytes < 0) return ((int)bytes); zip->entry_crc32 = crc32(zip->entry_crc32, p, bytes); @@ -580,11 +580,11 @@ compress_out(struct archive_write *a, const void *buff, size_t s, } while (zip->stream.avail_in); if (run == ARCHIVE_Z_FINISH) { uint64_t bytes = sizeof(zip->wbuff) - zip->stream.avail_out; - if (write_to_temp(a, zip->wbuff, bytes) != ARCHIVE_OK) + if (write_to_temp(a, zip->wbuff, (size_t)bytes) != ARCHIVE_OK) return (ARCHIVE_FATAL); if ((zip->crc32flg & ENCODED_CRC32) && bytes) zip->encoded_crc32 = crc32(zip->encoded_crc32, - zip->wbuff, bytes); + zip->wbuff, (unsigned)bytes); } return (s); @@ -599,7 +599,7 @@ _7z_write_data(struct archive_write *a, const void *buff, size_t s) zip = (struct _7zip *)a->format_data; if (s > zip->entry_bytes_remaining) - s = zip->entry_bytes_remaining; + s = (size_t)zip->entry_bytes_remaining; if (s == 0 || zip->cur_file == NULL) return (0); bytes = compress_out(a, buff, s, ARCHIVE_Z_RUN); @@ -622,7 +622,7 @@ _7z_finish_entry(struct archive_write *a) return (ARCHIVE_OK); while (zip->entry_bytes_remaining > 0) { - s = zip->entry_bytes_remaining; + s = (size_t)zip->entry_bytes_remaining; if (s > a->null_length) s = a->null_length; r = _7z_write_data(a, a->nulls, s); @@ -1676,10 +1676,10 @@ compression_init_encoder_deflate(struct archive *a, * a non-const pointer. */ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; strm->avail_in = lastrm->avail_in; - strm->total_in = lastrm->total_in; + strm->total_in = (uLong)lastrm->total_in; strm->next_out = lastrm->next_out; strm->avail_out = lastrm->avail_out; - strm->total_out = lastrm->total_out; + strm->total_out = (uLong)lastrm->total_out; if (deflateInit2(strm, level, Z_DEFLATED, (withheader)?15:-15, 8, Z_DEFAULT_STRATEGY) != Z_OK) { @@ -1709,10 +1709,10 @@ compression_code_deflate(struct archive *a, * a non-const pointer. */ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; strm->avail_in = lastrm->avail_in; - strm->total_in = lastrm->total_in; + strm->total_in = (uLong)lastrm->total_in; strm->next_out = lastrm->next_out; strm->avail_out = lastrm->avail_out; - strm->total_out = lastrm->total_out; + strm->total_out = (uLong)lastrm->total_out; r = deflate(strm, (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH); lastrm->next_in = strm->next_in; diff --git a/libarchive/archive_write_set_format_ar.c b/libarchive/archive_write_set_format_ar.c index 956b93228..beff49031 100644 --- a/libarchive/archive_write_set_format_ar.c +++ b/libarchive/archive_write_set_format_ar.c @@ -366,7 +366,7 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) ar = (struct ar_w *)a->format_data; if (s > ar->entry_bytes_remaining) - s = ar->entry_bytes_remaining; + s = (size_t)ar->entry_bytes_remaining; if (ar->is_strtab > 0) { if (ar->has_strtab > 0) { diff --git a/libarchive/archive_write_set_format_cpio.c b/libarchive/archive_write_set_format_cpio.c index 5d64cdcf0..e356703c4 100644 --- a/libarchive/archive_write_set_format_cpio.c +++ b/libarchive/archive_write_set_format_cpio.c @@ -188,7 +188,7 @@ synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) /* Don't store a mapping if we don't need to. */ if (archive_entry_nlink(entry) < 2) { - return ++cpio->ino_next; + return (int)(++cpio->ino_next); } /* Look up old ino; if we have it, this is a hardlink @@ -199,7 +199,7 @@ synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) } /* Assign a new index number. */ - ino_new = ++cpio->ino_next; + ino_new = (int)(++cpio->ino_next); /* Ensure space for the new mapping. */ if (cpio->ino_list_size <= cpio->ino_list_next) { @@ -388,7 +388,7 @@ archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s) cpio = (struct cpio *)a->format_data; if (s > cpio->entry_bytes_remaining) - s = cpio->entry_bytes_remaining; + s = (size_t)cpio->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); cpio->entry_bytes_remaining -= s; @@ -424,7 +424,7 @@ format_octal_recursive(int64_t v, char *p, int s) if (s == 0) return (v); v = format_octal_recursive(v, p+1, s-1); - *p = '0' + (v & 7); + *p = '0' + ((char)v & 7); return (v >> 3); } @@ -462,5 +462,6 @@ archive_write_cpio_finish_entry(struct archive_write *a) struct cpio *cpio; cpio = (struct cpio *)a->format_data; - return (__archive_write_nulls(a, cpio->entry_bytes_remaining)); + return (__archive_write_nulls(a, + (size_t)cpio->entry_bytes_remaining)); } diff --git a/libarchive/archive_write_set_format_cpio_newc.c b/libarchive/archive_write_set_format_cpio_newc.c index d7c2899ca..f16ac33e0 100644 --- a/libarchive/archive_write_set_format_cpio_newc.c +++ b/libarchive/archive_write_set_format_cpio_newc.c @@ -322,7 +322,7 @@ write_header(struct archive_write *a, struct archive_entry *entry) } cpio->entry_bytes_remaining = archive_entry_size(entry); - cpio->padding = PAD4(cpio->entry_bytes_remaining); + cpio->padding = (int)PAD4(cpio->entry_bytes_remaining); /* Write the symlink now. */ if (p != NULL && *p != '\0') { @@ -345,7 +345,7 @@ archive_write_newc_data(struct archive_write *a, const void *buff, size_t s) cpio = (struct cpio *)a->format_data; if (s > cpio->entry_bytes_remaining) - s = cpio->entry_bytes_remaining; + s = (size_t)cpio->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); cpio->entry_bytes_remaining -= s; @@ -418,5 +418,6 @@ archive_write_newc_finish_entry(struct archive_write *a) struct cpio *cpio; cpio = (struct cpio *)a->format_data; - return (__archive_write_nulls(a, cpio->entry_bytes_remaining + cpio->padding)); + return (__archive_write_nulls(a, + (size_t)cpio->entry_bytes_remaining + cpio->padding)); } diff --git a/libarchive/archive_write_set_format_gnutar.c b/libarchive/archive_write_set_format_gnutar.c index dc5b74488..dbb378c36 100644 --- a/libarchive/archive_write_set_format_gnutar.c +++ b/libarchive/archive_write_set_format_gnutar.c @@ -247,8 +247,8 @@ archive_write_gnutar_finish_entry(struct archive_write *a) int ret; gnutar = (struct gnutar *)a->format_data; - ret = __archive_write_nulls(a, - gnutar->entry_bytes_remaining + gnutar->entry_padding); + ret = __archive_write_nulls(a, (size_t) + (gnutar->entry_bytes_remaining + gnutar->entry_padding)); gnutar->entry_bytes_remaining = gnutar->entry_padding = 0; return (ret); } @@ -261,7 +261,7 @@ archive_write_gnutar_data(struct archive_write *a, const void *buff, size_t s) gnutar = (struct gnutar *)a->format_data; if (s > gnutar->entry_bytes_remaining) - s = gnutar->entry_bytes_remaining; + s = (size_t)gnutar->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); gnutar->entry_bytes_remaining -= s; if (ret != ARCHIVE_OK) diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c index 7c9d926ef..f4a3b98e0 100644 --- a/libarchive/archive_write_set_format_iso9660.c +++ b/libarchive/archive_write_set_format_iso9660.c @@ -1698,7 +1698,7 @@ wb_write_padding_to_temp(struct archive_write *a, int64_t csize) size_t ns; int ret; - ns = csize % LOGICAL_BLOCK_SIZE; + ns = (size_t)(csize % LOGICAL_BLOCK_SIZE); if (ns != 0) ret = write_null(a, LOGICAL_BLOCK_SIZE - ns); else @@ -1725,8 +1725,8 @@ write_iso9660_data(struct archive_write *a, const void *buff, size_t s) struct content *con; size_t ts; - ts = MULTI_EXTENT_SIZE - LOGICAL_BLOCK_SIZE - - iso9660->cur_file->cur_content->size; + ts = (size_t)(MULTI_EXTENT_SIZE - LOGICAL_BLOCK_SIZE - + iso9660->cur_file->cur_content->size); if (iso9660->zisofs.detect_magic) zisofs_detect_magic(a, buff, ts); @@ -1746,9 +1746,9 @@ write_iso9660_data(struct archive_write *a, const void *buff, size_t s) return (ARCHIVE_FATAL); /* Compute the logical block number. */ - iso9660->cur_file->cur_content->blocks = - (iso9660->cur_file->cur_content->size - + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + iso9660->cur_file->cur_content->blocks = (int) + ((iso9660->cur_file->cur_content->size + + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS); /* * Make next extent. @@ -1796,7 +1796,7 @@ iso9660_write_data(struct archive_write *a, const void *buff, size_t s) if (archive_entry_filetype(iso9660->cur_file->entry) != AE_IFREG) return (0); if (s > iso9660->bytes_remaining) - s = iso9660->bytes_remaining; + s = (size_t)iso9660->bytes_remaining; if (s == 0) return (0); @@ -1838,9 +1838,9 @@ iso9660_finish_entry(struct archive_write *a) return (ARCHIVE_FATAL); /* Compute the logical block number. */ - iso9660->cur_file->cur_content->blocks = - (iso9660->cur_file->cur_content->size - + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + iso9660->cur_file->cur_content->blocks = (int) + ((iso9660->cur_file->cur_content->size + + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS); /* Add the current file to data file list. */ isofile_add_data_file(iso9660, iso9660->cur_file); @@ -2547,7 +2547,7 @@ set_date_time(unsigned char *p, time_t t) set_digit(p+10, 2, tm.tm_min); set_digit(p+12, 2, tm.tm_sec); set_digit(p+14, 2, 0); - set_num_712(p+16, get_gmoffset(&tm)/(60*15)); + set_num_712(p+16, (char)(get_gmoffset(&tm)/(60*15))); } static void @@ -2569,7 +2569,7 @@ set_time_915(unsigned char *p, time_t t) set_num_711(p+3, tm.tm_hour); set_num_711(p+4, tm.tm_min); set_num_711(p+5, tm.tm_sec); - set_num_712(p+6, get_gmoffset(&tm)/(60*15)); + set_num_712(p+6, (char)(get_gmoffset(&tm)/(60*15))); } @@ -2941,8 +2941,8 @@ set_directory_record_rr(unsigned char *bp, int dr_len, bp = extra_next_record(&ctl, length); if (bp != NULL) { mode_t mode; - uid_t uid; - gid_t gid; + int64_t uid; + int64_t gid; mode = archive_entry_mode(file->entry); uid = archive_entry_uid(file->entry); @@ -2975,8 +2975,8 @@ set_directory_record_rr(unsigned char *bp, int dr_len, /* file links (stat.st_nlink) */ set_num_733(bp+13, archive_entry_nlink(file->entry)); - set_num_733(bp+21, uid); - set_num_733(bp+29, gid); + set_num_733(bp+21, (uint32_t)uid); + set_num_733(bp+29, (uint32_t)gid); /* File Serial Number */ if (pxent->dir) set_num_733(bp+37, pxent->dir_location); @@ -3357,8 +3357,8 @@ set_directory_record_rr(unsigned char *bp, int dr_len, bp[3] = length; bp[4] = 1; /* version */ dev = (uint64_t)archive_entry_rdev(file->entry); - set_num_733(bp + 5, dev >> 32); - set_num_733(bp + 13, dev & 0xFFFFFFFF); + set_num_733(bp + 5, (uint32_t)(dev >> 32)); + set_num_733(bp + 13, (uint32_t)(dev & 0xFFFFFFFF)); bp += length; } extra_tell_used_size(&ctl, length); @@ -3492,7 +3492,7 @@ set_directory_record(unsigned char *p, size_t n, struct isoent *isoent, set_num_733(bp+11, xisoent->dir_block * LOGICAL_BLOCK_SIZE); else - set_num_733(bp+11, file->cur_content->size); + set_num_733(bp+11, (uint32_t)file->cur_content->size); /* Recording Date and Time */ /* NOTE: * If a file type is symbolic link, you are seeing this @@ -3669,7 +3669,7 @@ wb_set_offset(struct archive_write *a, int64_t off) iso9660->wbuff_tail = iso9660->wbuff_offset + used; if (iso9660->wbuff_offset < iso9660->wbuff_written) { if (used > 0 && - write_to_temp(a, iso9660->wbuff, used) != ARCHIVE_OK) + write_to_temp(a, iso9660->wbuff, (size_t)used) != ARCHIVE_OK) return (ARCHIVE_FATAL); iso9660->wbuff_offset = iso9660->wbuff_written; lseek(iso9660->temp_fd, iso9660->wbuff_offset, SEEK_SET); @@ -3688,12 +3688,12 @@ wb_set_offset(struct archive_write *a, int64_t off) iso9660->wbuff_offset = off; iso9660->wbuff_remaining = sizeof(iso9660->wbuff); } else if (off <= iso9660->wbuff_tail) { - iso9660->wbuff_remaining = - sizeof(iso9660->wbuff) - (off - iso9660->wbuff_offset); + iso9660->wbuff_remaining = (size_t) + (sizeof(iso9660->wbuff) - (off - iso9660->wbuff_offset)); } else { ext_bytes = off - iso9660->wbuff_tail; - iso9660->wbuff_remaining = sizeof(iso9660->wbuff) - - (iso9660->wbuff_tail - iso9660->wbuff_offset); + iso9660->wbuff_remaining = (size_t)(sizeof(iso9660->wbuff) + - (iso9660->wbuff_tail - iso9660->wbuff_offset)); while (ext_bytes >= (int64_t)iso9660->wbuff_remaining) { if (write_null(a, (size_t)iso9660->wbuff_remaining) != ARCHIVE_OK) @@ -5438,8 +5438,8 @@ isoent_setup_file_location(struct iso9660 *iso9660, int location) iso9660->total_file_block = 0; if ((isoent = iso9660->el_torito.catalog) != NULL) { isoent->file->content.location = location; - block = (archive_entry_size(isoent->file->entry) + - LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + block = (int)((archive_entry_size(isoent->file->entry) + + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS); location += block; iso9660->total_file_block += block; } @@ -5447,7 +5447,7 @@ isoent_setup_file_location(struct iso9660 *iso9660, int location) isoent->file->content.location = location; size = fd_boot_image_size(iso9660->el_torito.media_type); if (size == 0) - size = archive_entry_size(isoent->file->entry); + size = (size_t)archive_entry_size(isoent->file->entry); block = (size + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; location += block; iso9660->total_file_block += block; @@ -7425,7 +7425,8 @@ zisofs_init(struct archive_write *a, struct isofile *file) /* Mark file->zisofs to create RRIP 'ZF' Use Entry. */ file->zisofs.header_size = ZF_HEADER_SIZE >> 2; file->zisofs.log2_bs = ZF_LOG2_BS; - file->zisofs.uncompressed_size = archive_entry_size(file->entry); + file->zisofs.uncompressed_size = + (uint32_t)archive_entry_size(file->entry); /* Calculate a size of Block Pointers of zisofs. */ ceil = (file->zisofs.uncompressed_size + ZF_BLOCK_SIZE -1) @@ -7453,13 +7454,14 @@ zisofs_init(struct archive_write *a, struct isofile *file) * file. */ tsize = ZF_HEADER_SIZE + bpsize; - if (write_null(a, tsize) != ARCHIVE_OK) + if (write_null(a, (size_t)tsize) != ARCHIVE_OK) return (ARCHIVE_FATAL); /* * Initialize some variables to make zisofs. */ - archive_le32enc(&(iso9660->zisofs.block_pointers[0]), tsize); + archive_le32enc(&(iso9660->zisofs.block_pointers[0]), + (uint32_t)tsize); iso9660->zisofs.remaining = file->zisofs.uncompressed_size; iso9660->zisofs.making = 1; iso9660->zisofs.allzero = 1; @@ -7488,7 +7490,7 @@ zisofs_detect_magic(struct archive_write *a, const void *buff, size_t s) entry_size = archive_entry_size(file->entry); if ((int64_t)sizeof(iso9660->zisofs.magic_buffer) > entry_size) - magic_max = entry_size; + magic_max = (int)entry_size; else magic_max = sizeof(iso9660->zisofs.magic_buffer); @@ -7664,7 +7666,7 @@ zisofs_write_to_temp(struct archive_write *a, const void *buff, size_t s) iso9660->zisofs.block_pointers_idx ++; archive_le32enc(&(iso9660->zisofs.block_pointers[ iso9660->zisofs.block_pointers_idx]), - iso9660->zisofs.total_size); + (uint32_t)iso9660->zisofs.total_size); r = zisofs_init_zstream(a); if (r != ARCHIVE_OK) return (ARCHIVE_FATAL); @@ -7793,9 +7795,9 @@ zisofs_extract_init(struct archive_write *a, struct zisofs_extract *zisofs, size_t ceil, xsize; /* Allocate block pointers buffer. */ - ceil = (zisofs->pz_uncompressed_size + + ceil = (size_t)((zisofs->pz_uncompressed_size + (((int64_t)1) << zisofs->pz_log2_bs) - 1) - >> zisofs->pz_log2_bs; + >> zisofs->pz_log2_bs); xsize = (ceil + 1) * 4; if (zisofs->block_pointers == NULL) { size_t alloc = ((xsize >> 10) + 1) << 10; @@ -8016,7 +8018,7 @@ zisofs_rewind_boot_file(struct archive_write *a) fd = iso9660->temp_fd; new_offset = wb_offset(a); read_offset = file->content.offset_of_temp; - remaining = file->content.size; + remaining = (size_t)file->content.size; if (remaining > 1024 * 32) rbuff_size = 1024 * 32; else diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index 28e57220f..4b300012f 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -1079,7 +1079,7 @@ archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) struct mtree_writer *mtree= a->format_data; if (n > mtree->entry_bytes_remaining) - n = mtree->entry_bytes_remaining; + n = (size_t)mtree->entry_bytes_remaining; mtree->entry_bytes_remaining -= n; /* We don't need to compute a regular file sum */ diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index 742b9ebdd..2c2ef308a 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -1263,7 +1263,7 @@ archive_write_pax_header(struct archive_write *a, return (ARCHIVE_FATAL); } /* Pad out the end of the entry. */ - r = __archive_write_nulls(a, pax->entry_padding); + r = __archive_write_nulls(a, (size_t)pax->entry_padding); if (r != ARCHIVE_OK) { /* If a write fails, we're pretty much toast. */ return (ARCHIVE_FATAL); @@ -1605,7 +1605,7 @@ archive_write_pax_finish_entry(struct archive_write *a) pax->sparse_list = sb; } } - ret = __archive_write_nulls(a, remaining + pax->entry_padding); + ret = __archive_write_nulls(a, (size_t)(remaining + pax->entry_padding)); pax->entry_bytes_remaining = pax->entry_padding = 0; return (ret); } @@ -1652,7 +1652,7 @@ archive_write_pax_data(struct archive_write *a, const void *buff, size_t s) p = ((const unsigned char *)buff) + total; ws = s - total; if (ws > pax->sparse_list->remaining) - ws = pax->sparse_list->remaining; + ws = (size_t)pax->sparse_list->remaining; if (pax->sparse_list->is_hole) { /* Current block is hole thus we do not write diff --git a/libarchive/archive_write_set_format_ustar.c b/libarchive/archive_write_set_format_ustar.c index 3117dd364..1bc2372c9 100644 --- a/libarchive/archive_write_set_format_ustar.c +++ b/libarchive/archive_write_set_format_ustar.c @@ -672,7 +672,7 @@ archive_write_ustar_finish_entry(struct archive_write *a) ustar = (struct ustar *)a->format_data; ret = __archive_write_nulls(a, - ustar->entry_bytes_remaining + ustar->entry_padding); + (size_t)(ustar->entry_bytes_remaining + ustar->entry_padding)); ustar->entry_bytes_remaining = ustar->entry_padding = 0; return (ret); } @@ -685,7 +685,7 @@ archive_write_ustar_data(struct archive_write *a, const void *buff, size_t s) ustar = (struct ustar *)a->format_data; if (s > ustar->entry_bytes_remaining) - s = ustar->entry_bytes_remaining; + s = (size_t)ustar->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); ustar->entry_bytes_remaining -= s; if (ret != ARCHIVE_OK) diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c index 642a17b9f..17f5ba635 100644 --- a/libarchive/archive_write_set_format_xar.c +++ b/libarchive/archive_write_set_format_xar.c @@ -656,7 +656,7 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s) xar = (struct xar *)a->format_data; if (s > xar->bytes_remaining) - s = xar->bytes_remaining; + s = (size_t)xar->bytes_remaining; if (s == 0 || xar->cur_file == NULL) return (0); if (xar->cur_file->data.compression == NONE) { @@ -737,7 +737,7 @@ xar_finish_entry(struct archive_write *a) return (ARCHIVE_OK); while (xar->bytes_remaining > 0) { - s = xar->bytes_remaining; + s = (size_t)xar->bytes_remaining; if (s > a->null_length) s = a->null_length; w = xar_write_data(a, a->nulls, s); @@ -2596,10 +2596,10 @@ compression_init_encoder_gzip(struct archive *a, * a non-const pointer. */ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; strm->avail_in = lastrm->avail_in; - strm->total_in = lastrm->total_in; + strm->total_in = (uLong)lastrm->total_in; strm->next_out = lastrm->next_out; strm->avail_out = lastrm->avail_out; - strm->total_out = lastrm->total_out; + strm->total_out = (uLong)lastrm->total_out; if (deflateInit2(strm, level, Z_DEFLATED, (withheader)?15:-15, 8, Z_DEFAULT_STRATEGY) != Z_OK) { @@ -2629,10 +2629,10 @@ compression_code_gzip(struct archive *a, * a non-const pointer. */ strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; strm->avail_in = lastrm->avail_in; - strm->total_in = lastrm->total_in; + strm->total_in = (uLong)lastrm->total_in; strm->next_out = lastrm->next_out; strm->avail_out = lastrm->avail_out; - strm->total_out = lastrm->total_out; + strm->total_out = (uLong)lastrm->total_out; r = deflate(strm, (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH); lastrm->next_in = strm->next_in; diff --git a/libarchive/archive_write_set_format_zip.c b/libarchive/archive_write_set_format_zip.c index 8fc10ef57..60a8ad821 100644 --- a/libarchive/archive_write_set_format_zip.c +++ b/libarchive/archive_write_set_format_zip.c @@ -478,12 +478,15 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) * specification says to set to zero when using data * descriptors. Otherwise the end of the data for an * entry is rather difficult to find. */ - archive_le32enc(&h[LOCAL_FILE_HEADER_COMPRESSED_SIZE], size); - archive_le32enc(&h[LOCAL_FILE_HEADER_UNCOMPRESSED_SIZE], size); + archive_le32enc(&h[LOCAL_FILE_HEADER_COMPRESSED_SIZE], + (uint32_t)size); + archive_le32enc(&h[LOCAL_FILE_HEADER_UNCOMPRESSED_SIZE], + (uint32_t)size); break; #ifdef HAVE_ZLIB_H case COMPRESSION_DEFLATE: - archive_le32enc(&h[LOCAL_FILE_HEADER_UNCOMPRESSED_SIZE], size); + archive_le32enc(&h[LOCAL_FILE_HEADER_UNCOMPRESSED_SIZE], + (uint32_t)size); zip->stream.zalloc = Z_NULL; zip->stream.zfree = Z_NULL; @@ -506,9 +509,12 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) ZIP_SIGNATURE_EXTRA_TIMESTAMP); archive_le16enc(&e[EXTRA_DATA_LOCAL_TIME_SIZE], 1 + 4 * 3); e[EXTRA_DATA_LOCAL_TIME_FLAG] = 0x07; - archive_le32enc(&e[EXTRA_DATA_LOCAL_MTIME], archive_entry_mtime(entry)); - archive_le32enc(&e[EXTRA_DATA_LOCAL_ATIME], archive_entry_atime(entry)); - archive_le32enc(&e[EXTRA_DATA_LOCAL_CTIME], archive_entry_ctime(entry)); + archive_le32enc(&e[EXTRA_DATA_LOCAL_MTIME], + (uint32_t)archive_entry_mtime(entry)); + archive_le32enc(&e[EXTRA_DATA_LOCAL_ATIME], + (uint32_t)archive_entry_atime(entry)); + archive_le32enc(&e[EXTRA_DATA_LOCAL_CTIME], + (uint32_t)archive_entry_ctime(entry)); archive_le16enc(&e[EXTRA_DATA_LOCAL_UNIX_ID], ZIP_SIGNATURE_EXTRA_NEW_UNIX); @@ -516,12 +522,13 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) e[EXTRA_DATA_LOCAL_UNIX_VERSION] = 1; e[EXTRA_DATA_LOCAL_UNIX_UID_SIZE] = 4; archive_le32enc(&e[EXTRA_DATA_LOCAL_UNIX_UID], - archive_entry_uid(entry)); + (uint32_t)archive_entry_uid(entry)); e[EXTRA_DATA_LOCAL_UNIX_GID_SIZE] = 4; archive_le32enc(&e[EXTRA_DATA_LOCAL_UNIX_GID], - archive_entry_gid(entry)); + (uint32_t)archive_entry_gid(entry)); - archive_le32enc(&d[DATA_DESCRIPTOR_UNCOMPRESSED_SIZE], size); + archive_le32enc(&d[DATA_DESCRIPTOR_UNCOMPRESSED_SIZE], + (uint32_t)size); ret = __archive_write_output(a, h, sizeof(h)); if (ret != ARCHIVE_OK) @@ -542,11 +549,11 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) const unsigned char *p; p = (const unsigned char *)archive_entry_symlink(l->entry); - ret = __archive_write_output(a, p, size); + ret = __archive_write_output(a, p, (size_t)size); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); zip->written_bytes += size; - l->crc32 = crc32(l->crc32, p, size); + l->crc32 = crc32(l->crc32, p, (unsigned)size); } if (ret2 != ARCHIVE_OK) @@ -646,7 +653,7 @@ archive_write_zip_finish_entry(struct archive_write *a) archive_le32enc(&d[DATA_DESCRIPTOR_CRC32], l->crc32); archive_le32enc(&d[DATA_DESCRIPTOR_COMPRESSED_SIZE], - l->compressed_size); + (uint32_t)l->compressed_size); ret = __archive_write_output(a, d, SIZE_DATA_DESCRIPTOR); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); @@ -695,15 +702,15 @@ archive_write_zip_close(struct archive_write *a) dos_time(archive_entry_mtime(l->entry))); archive_le32enc(&h[FILE_HEADER_CRC32], l->crc32); archive_le32enc(&h[FILE_HEADER_COMPRESSED_SIZE], - l->compressed_size); + (uint32_t)l->compressed_size); archive_le32enc(&h[FILE_HEADER_UNCOMPRESSED_SIZE], - archive_entry_size(l->entry)); + (uint32_t)archive_entry_size(l->entry)); archive_le16enc(&h[FILE_HEADER_FILENAME_LENGTH], (uint16_t)path_length(l->entry)); archive_le16enc(&h[FILE_HEADER_EXTRA_LENGTH], sizeof(e)); archive_le16enc(&h[FILE_HEADER_ATTRIBUTES_EXTERNAL+2], archive_entry_mode(l->entry)); - archive_le32enc(&h[FILE_HEADER_OFFSET], l->offset); + archive_le32enc(&h[FILE_HEADER_OFFSET], (uint32_t)l->offset); /* Formatting extra data. */ archive_le16enc(&e[EXTRA_DATA_CENTRAL_TIME_ID], @@ -711,7 +718,7 @@ archive_write_zip_close(struct archive_write *a) archive_le16enc(&e[EXTRA_DATA_CENTRAL_TIME_SIZE], 1 + 4); e[EXTRA_DATA_CENTRAL_TIME_FLAG] = 0x07; archive_le32enc(&e[EXTRA_DATA_CENTRAL_MTIME], - archive_entry_mtime(l->entry)); + (uint32_t)archive_entry_mtime(l->entry)); archive_le16enc(&e[EXTRA_DATA_CENTRAL_UNIX_ID], ZIP_SIGNATURE_EXTRA_NEW_UNIX); archive_le16enc(&e[EXTRA_DATA_CENTRAL_UNIX_SIZE], 0x0000); @@ -743,8 +750,9 @@ archive_write_zip_close(struct archive_write *a) archive_le16enc(&end[CENTRAL_DIRECTORY_END_ENTRIES_DISK], entries); archive_le16enc(&end[CENTRAL_DIRECTORY_END_ENTRIES], entries); archive_le32enc(&end[CENTRAL_DIRECTORY_END_SIZE], - offset_end - offset_start); - archive_le32enc(&end[CENTRAL_DIRECTORY_END_OFFSET], offset_start); + (uint32_t)(offset_end - offset_start)); + archive_le32enc(&end[CENTRAL_DIRECTORY_END_OFFSET], + (uint32_t)offset_start); /* Writing end of central directory. */ ret = __archive_write_output(a, end, sizeof(end));