From: Tobias Stoeckmann Date: Sat, 18 Jul 2026 17:09:12 +0000 (+0200) Subject: Unify format data handling X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a631287e4cc962eea7530a8f8d510452f0fc3dce;p=thirdparty%2Flibarchive.git Unify format data handling - Declare access variable at the beginning - Remove unneeded cast (see warc parser, which never did it) - Remove inline cast function - Avoid unneeded brackets to unify style Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_read_support_format_7zip.c b/libarchive/archive_read_support_format_7zip.c index 25eb94161..9c9f9a0ee 100644 --- a/libarchive/archive_read_support_format_7zip.c +++ b/libarchive/archive_read_support_format_7zip.c @@ -520,7 +520,7 @@ static int archive_read_format_7zip_has_encrypted_entries(struct archive_read *a) { if (a && a->format) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; if (zip) { return zip->has_encrypted_entries; } @@ -894,7 +894,7 @@ static int archive_read_format_7zip_read_header(struct archive_read *a, struct archive_entry *entry) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; struct _7zip_entry *zip_entry; int r, ret = ARCHIVE_OK; struct _7z_folder *folder = 0; @@ -1095,12 +1095,10 @@ static int archive_read_format_7zip_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct _7zip *zip; + struct _7zip *zip = a->format->data; ssize_t bytes; int ret = ARCHIVE_OK; - zip = (struct _7zip *)(a->format->data); - if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { zip->has_encrypted_entries = 0; } @@ -1165,11 +1163,9 @@ archive_read_format_7zip_read_data(struct archive_read *a, static int archive_read_format_7zip_read_data_skip(struct archive_read *a) { - struct _7zip *zip; + struct _7zip *zip = a->format->data; int r; - zip = (struct _7zip *)(a->format->data); - if (zip->pack_stream_bytes_unconsumed) read_consume(a); @@ -1194,9 +1190,8 @@ archive_read_format_7zip_read_data_skip(struct archive_read *a) static int archive_read_format_7zip_cleanup(struct archive_read *a) { - struct _7zip *zip; + struct _7zip *zip = a->format->data; - zip = (struct _7zip *)(a->format->data); free_StreamsInfo(&(zip->si)); free(zip->entries); free(zip->entry_names); @@ -1207,14 +1202,14 @@ archive_read_format_7zip_cleanup(struct archive_read *a) free(zip->sub_stream_buff[2]); free(zip->tmp_stream_buff); free(zip); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } static int read_consume(struct archive_read *a) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; if (zip->pack_stream_bytes_unconsumed) { int64_t r; @@ -1298,7 +1293,7 @@ static Byte ppmd_read(void *p) { struct archive_read *a = ((IByteIn*)p)->a; - struct _7zip *zip = (struct _7zip *)(a->format->data); + struct _7zip *zip = a->format->data; Byte b; if (zip->ppstream.avail_in == 0) { @@ -2258,7 +2253,7 @@ free_Folder(struct _7z_folder *f) static int read_Folder(struct archive_read *a, struct _7z_folder *f) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const unsigned char *p; size_t numInStreamsTotal = 0; size_t numOutStreamsTotal = 0; @@ -2404,7 +2399,7 @@ free_CodersInfo(struct _7z_coders_info *ci) static int read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const unsigned char *p; struct _7z_digests digest; size_t dataStreamIndex, i; @@ -2686,7 +2681,7 @@ free_StreamsInfo(struct _7z_stream_info *si) static int read_StreamsInfo(struct archive_read *a, struct _7z_stream_info *si) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const unsigned char *p; size_t i; @@ -2788,7 +2783,7 @@ static int read_Header(struct archive_read *a, struct _7z_header_info *h, int check_header_id) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const unsigned char *p; struct _7z_folder *folders; struct _7z_stream_info *si = &(zip->si); @@ -3146,7 +3141,7 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, static int read_Times(struct archive_read *a, int type) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const unsigned char *p; struct _7zip_entry *entries = zip->entries; unsigned char *timeBools = NULL; @@ -3211,7 +3206,7 @@ failed: static int decode_encoded_header_info(struct archive_read *a, struct _7z_stream_info *si) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; int64_t pi_end; errno = 0; @@ -3246,7 +3241,7 @@ decode_encoded_header_info(struct archive_read *a, struct _7z_stream_info *si) static const unsigned char * header_bytes(struct archive_read *a, size_t rbytes) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const unsigned char *p; if ((uint64_t)zip->header_bytes_remaining < rbytes) @@ -3460,7 +3455,7 @@ static ssize_t get_uncompressed_data(struct archive_read *a, const void **buff, size_t size, size_t minimum) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; ssize_t bytes_avail; if (zip->codec == _7Z_COPY && zip->codec2 == -1) { @@ -3523,7 +3518,7 @@ align_size(size_t s) static ssize_t extract_pack_stream(struct archive_read *a, size_t minimum) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; ssize_t bytes_avail; int r; @@ -3681,7 +3676,7 @@ extract_pack_stream(struct archive_read *a, size_t minimum) static int seek_pack(struct archive_read *a) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; int64_t pack_offset; if (zip->pack_stream_remaining == 0) { @@ -3712,7 +3707,7 @@ static ssize_t read_stream(struct archive_read *a, const void **buff, size_t size, size_t minimum) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; int64_t skip_bytes = 0; ssize_t r; @@ -3831,7 +3826,7 @@ static int setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, int header) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const struct _7z_coder *coder1, *coder2; const char *cname = (header)?"archive header":"file content"; size_t i; @@ -4099,7 +4094,7 @@ setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, static int skip_stream(struct archive_read *a, int64_t skip_bytes) { - struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip *zip = a->format->data; const void *p; int64_t skipped_bytes; int64_t bytes = skip_bytes; diff --git a/libarchive/archive_read_support_format_ar.c b/libarchive/archive_read_support_format_ar.c index 6286faa03..8585de28f 100644 --- a/libarchive/archive_read_support_format_ar.c +++ b/libarchive/archive_read_support_format_ar.c @@ -135,7 +135,7 @@ archive_read_support_format_ar(struct archive *_a) static int archive_read_format_ar_cleanup(struct archive_read *a) { - struct ar *ar = (struct ar *)(a->format->data); + struct ar *ar = a->format->data; free(ar->strtab); free(ar); @@ -399,7 +399,7 @@ static int archive_read_format_ar_read_header(struct archive_read *a, struct archive_entry *entry) { - struct ar *ar = (struct ar *)(a->format->data); + struct ar *ar = a->format->data; int64_t unconsumed; const void *header_data; int ret; @@ -459,7 +459,7 @@ static int archive_read_format_ar_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct ar *ar = (struct ar *)(a->format->data); + struct ar *ar = a->format->data; ssize_t bytes_read; if (ar->entry_bytes_unconsumed) { @@ -498,7 +498,7 @@ archive_read_format_ar_read_data(struct archive_read *a, static int archive_read_format_ar_skip(struct archive_read *a) { - struct ar *ar = (struct ar *)(a->format->data); + struct ar *ar = a->format->data; if (__archive_read_consume(a, ar->entry_bytes_remaining + ar->entry_padding + @@ -515,7 +515,7 @@ archive_read_format_ar_skip(struct archive_read *a) static int ar_parse_gnu_filename_table(struct archive_read *a) { - struct ar *ar = (struct ar *)(a->format->data); + struct ar *ar = a->format->data; char *p; size_t size; diff --git a/libarchive/archive_read_support_format_cab.c b/libarchive/archive_read_support_format_cab.c index 0bf769d79..f90250e19 100644 --- a/libarchive/archive_read_support_format_cab.c +++ b/libarchive/archive_read_support_format_cab.c @@ -566,10 +566,9 @@ static int archive_read_format_cab_options(struct archive_read *a, const char *key, const char *val) { - struct cab *cab; + struct cab *cab = a->format->data; int ret = ARCHIVE_FAILED; - cab = (struct cab *)(a->format->data); if (strcmp(key, "hdrcharset") == 0) { if (val == NULL || val[0] == 0) archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, @@ -725,8 +724,8 @@ cab_convert_path_separator_2(struct cab *cab, struct archive_entry *entry) static int cab_read_header(struct archive_read *a) { + struct cab *cab = a->format->data; const char *p; - struct cab *cab; struct cfheader *hd; size_t bytes, len, maxlen, used; ssize_t avail; @@ -742,7 +741,6 @@ cab_read_header(struct archive_read *a) if ((p = __archive_read_ahead(a, 42, NULL)) == NULL) return (truncated_error(a)); - cab = (struct cab *)(a->format->data); if (cab->found_header == 0 && p[0] == 'M' && p[1] == 'Z') { /* This is an executable? Must be self-extracting... */ @@ -1005,14 +1003,13 @@ static int archive_read_format_cab_read_header(struct archive_read *a, struct archive_entry *entry) { - struct cab *cab; + struct cab *cab = a->format->data; struct cfheader *hd; struct cffolder *prev_folder; struct cffile *file; struct archive_string_conv *sconv; int err = ARCHIVE_OK, r; - - cab = (struct cab *)(a->format->data); + if (cab->found_header == 0) { err = cab_read_header(a); if (err < ARCHIVE_WARN) @@ -1127,7 +1124,7 @@ static int archive_read_format_cab_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; int r; switch (cab->entry_cffile->folder) { @@ -1227,7 +1224,7 @@ cab_checksum_cfdata(const void *p, size_t bytes, uint32_t seed) static void cab_checksum_update(struct archive_read *a, size_t bytes) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata = cab->entry_cfdata; const unsigned char *p; size_t sumbytes; @@ -1267,7 +1264,7 @@ cab_checksum_update(struct archive_read *a, size_t bytes) static int cab_checksum_finish(struct archive_read *a) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata = cab->entry_cfdata; int l; @@ -1312,7 +1309,7 @@ cab_checksum_finish(struct archive_read *a) static int cab_next_cfdata(struct archive_read *a) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata = cab->entry_cfdata; /* There are remaining bytes in current CFDATA, use it first. */ @@ -1460,7 +1457,7 @@ invalid: static const void * cab_read_ahead_cfdata(struct archive_read *a, ssize_t *avail) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; int err; err = cab_next_cfdata(a); @@ -1491,7 +1488,7 @@ cab_read_ahead_cfdata(struct archive_read *a, ssize_t *avail) static const void * cab_read_ahead_cfdata_none(struct archive_read *a, ssize_t *avail) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata; const void *d; @@ -1523,7 +1520,7 @@ cab_read_ahead_cfdata_none(struct archive_read *a, ssize_t *avail) static const void * cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata; const void *d; int r, mszip; @@ -1751,7 +1748,7 @@ cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail) static const void * cab_read_ahead_cfdata_lzx(struct archive_read *a, ssize_t *avail) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata; const void *d; int r; @@ -1881,7 +1878,7 @@ cab_read_ahead_cfdata_lzx(struct archive_read *a, ssize_t *avail) static int64_t cab_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata; int64_t cbytes, rbytes; int err; @@ -1974,7 +1971,7 @@ cab_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) static int64_t cab_minimum_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfdata *cfdata; int64_t cbytes, rbytes; int err; @@ -2031,7 +2028,7 @@ static int cab_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; ssize_t bytes_avail; if (cab->entry_bytes_remaining == 0) { @@ -2077,12 +2074,10 @@ cab_read_data(struct archive_read *a, const void **buff, static int archive_read_format_cab_read_data_skip(struct archive_read *a) { - struct cab *cab; + struct cab *cab = a->format->data; int64_t bytes_skipped; int r; - cab = (struct cab *)(a->format->data); - if (cab->end_of_archive) return (ARCHIVE_EOF); @@ -2132,7 +2127,7 @@ archive_read_format_cab_read_data_skip(struct archive_read *a) static int archive_read_format_cab_cleanup(struct archive_read *a) { - struct cab *cab = (struct cab *)(a->format->data); + struct cab *cab = a->format->data; struct cfheader *hd = &cab->cfheader; uint16_t i; @@ -2154,7 +2149,7 @@ archive_read_format_cab_cleanup(struct archive_read *a) archive_wstring_free(&cab->ws); free(cab->uncompressed_buffer); free(cab); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index 7341aa0c1..ab51b473c 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -261,14 +261,12 @@ archive_read_support_format_cpio(struct archive *_a) static int archive_read_format_cpio_bid(struct archive_read *a, int best_bid) { + struct cpio *cpio = a->format->data; const unsigned char *p; - struct cpio *cpio; int bid; (void)best_bid; /* UNUSED */ - cpio = (struct cpio *)(a->format->data); - if ((p = __archive_read_ahead(a, 6, NULL)) == NULL) return (-1); @@ -326,10 +324,9 @@ static int archive_read_format_cpio_options(struct archive_read *a, const char *key, const char *val) { - struct cpio *cpio; + struct cpio *cpio = a->format->data; int ret = ARCHIVE_FAILED; - cpio = (struct cpio *)(a->format->data); if (strcmp(key, "compat-2x") == 0) { /* Handle filenames as libarchive 2.x */ cpio->init_default_conversion = (val != NULL)?1:0; @@ -364,7 +361,7 @@ static int archive_read_format_cpio_read_header(struct archive_read *a, struct archive_entry *entry) { - struct cpio *cpio; + struct cpio *cpio = a->format->data; const void *h, *hl; struct archive_string_conv *sconv; size_t namelength; @@ -372,7 +369,6 @@ archive_read_format_cpio_read_header(struct archive_read *a, int is_trailer; int r; - cpio = (struct cpio *)(a->format->data); sconv = cpio->opt_sconv; if (sconv == NULL) { if (!cpio->init_default_conversion) { @@ -473,10 +469,8 @@ static int archive_read_format_cpio_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { + struct cpio *cpio = a->format->data; ssize_t bytes_read; - struct cpio *cpio; - - cpio = (struct cpio *)(a->format->data); if (cpio->entry_bytes_unconsumed) { __archive_read_consume(a, cpio->entry_bytes_unconsumed); @@ -511,7 +505,7 @@ archive_read_format_cpio_read_data(struct archive_read *a, static int archive_read_format_cpio_skip(struct archive_read *a) { - struct cpio *cpio = (struct cpio *)(a->format->data); + struct cpio *cpio = a->format->data; int64_t to_skip = cpio->entry_bytes_remaining + cpio->entry_padding + cpio->entry_bytes_unconsumed; @@ -1004,9 +998,8 @@ header_bin_be(struct archive_read *a, struct cpio *cpio, static int archive_read_format_cpio_cleanup(struct archive_read *a) { - struct cpio *cpio; + struct cpio *cpio = a->format->data; - cpio = (struct cpio *)(a->format->data); /* Free inode->name map */ while (cpio->links_head != NULL) { struct links_entry *lp = cpio->links_head->next; @@ -1016,7 +1009,7 @@ archive_read_format_cpio_cleanup(struct archive_read *a) cpio->links_head = lp; } free(cpio); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } diff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c index 17c91f3fe..59cfa791e 100644 --- a/libarchive/archive_read_support_format_iso9660.c +++ b/libarchive/archive_read_support_format_iso9660.c @@ -504,7 +504,7 @@ archive_read_support_format_iso9660(struct archive *_a) static int archive_read_format_iso9660_bid(struct archive_read *a, int best_bid) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; ssize_t bytes_read; const unsigned char *p; int seenTerminator; @@ -514,8 +514,6 @@ archive_read_format_iso9660_bid(struct archive_read *a, int best_bid) if (best_bid > 48) return (-1); - iso9660 = (struct iso9660 *)(a->format->data); - /* * Skip the first 32k (reserved area) and get the first * 8 sectors of the volume descriptor table. Of course, @@ -577,9 +575,7 @@ static int archive_read_format_iso9660_options(struct archive_read *a, const char *key, const char *val) { - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); + struct iso9660 *iso9660 = a->format->data; if (strcmp(key, "joliet") == 0) { if (val == NULL || strcmp(val, "off") == 0 || @@ -1035,12 +1031,11 @@ isRootDirectoryRecord(const unsigned char *p) { static int read_children(struct archive_read *a, struct file_info *parent) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; const unsigned char *b, *p; struct file_info *multi; size_t step, skip_size; - iso9660 = (struct iso9660 *)(a->format->data); /* flush any remaining bytes from the last round to ensure * we're positioned */ if (iso9660->entry_bytes_unconsumed) { @@ -1248,12 +1243,10 @@ static int archive_read_format_iso9660_read_header(struct archive_read *a, struct archive_entry *entry) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; struct file_info *file; int r, rd_r = ARCHIVE_OK; - iso9660 = (struct iso9660 *)(a->format->data); - if (!a->archive.archive_format) { a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; a->archive.archive_format_name = "ISO9660"; @@ -1500,7 +1493,7 @@ static int zisofs_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; struct zisofs *zisofs; const unsigned char *p; size_t avail; @@ -1508,7 +1501,6 @@ zisofs_read_data(struct archive_read *a, size_t uncompressed_size; int r; - iso9660 = (struct iso9660 *)(a->format->data); zisofs = &iso9660->entry_zisofs; p = __archive_read_ahead(a, 1, &bytes_read); @@ -1739,10 +1731,8 @@ static int archive_read_format_iso9660_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { + struct iso9660 *iso9660 = a->format->data; ssize_t bytes_read; - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); if (iso9660->entry_bytes_unconsumed) { __archive_read_consume(a, iso9660->entry_bytes_unconsumed); @@ -1806,10 +1796,9 @@ archive_read_format_iso9660_read_data(struct archive_read *a, static int archive_read_format_iso9660_cleanup(struct archive_read *a) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; int r = ARCHIVE_OK; - iso9660 = (struct iso9660 *)(a->format->data); release_files(iso9660); free(iso9660->read_ce_req.reqs); archive_string_free(&iso9660->pathname); @@ -1829,7 +1818,7 @@ archive_read_format_iso9660_cleanup(struct archive_read *a) free(iso9660->utf16be_path); free(iso9660->utf16be_previous_path); free(iso9660); - (a->format->data) = NULL; + a->format->data = NULL; return (r); } @@ -1841,7 +1830,7 @@ static struct file_info * parse_file_info(struct archive_read *a, struct file_info *parent, const unsigned char *isodirrec, size_t reclen) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; struct file_info *file, *filep; size_t name_len; const unsigned char *rr_start, *rr_end; @@ -1851,8 +1840,6 @@ parse_file_info(struct archive_read *a, struct file_info *parent, int32_t location; int flags; - iso9660 = (struct iso9660 *)(a->format->data); - if (reclen != 0) dr_len = (size_t)isodirrec[DR_length_offset]; /* @@ -2193,11 +2180,9 @@ static int parse_rockridge(struct archive_read *a, struct file_info *file, const unsigned char *p, const unsigned char *end) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; int entry_seen = 0; - iso9660 = (struct iso9660 *)(a->format->data); - while (p + 4 <= end /* Enough space for another entry. */ && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */ @@ -2367,12 +2352,11 @@ static int register_CE(struct archive_read *a, int32_t location, struct file_info *file) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format->data; struct read_ce_queue *heap; uint64_t offset, parent_offset; size_t hole, parent; - iso9660 = (struct iso9660 *)(a->format->data); offset = ((uint64_t)location) * (uint64_t)iso9660->logical_block_size; if (((file->mode & AE_IFMT) == AE_IFREG && offset >= file->offset) || diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index 675c9f399..0a4754615 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -390,10 +390,9 @@ static int archive_read_format_lha_options(struct archive_read *a, const char *key, const char *val) { - struct lha *lha; + struct lha *lha = a->format->data; int ret = ARCHIVE_FAILED; - lha = (struct lha *)(a->format->data); if (strcmp(key, "hdrcharset") == 0) { if (val == NULL || val[0] == 0) archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, @@ -472,9 +471,9 @@ static int archive_read_format_lha_read_header(struct archive_read *a, struct archive_entry *entry) { + struct lha *lha = a->format->data; struct archive_wstring linkname; struct archive_wstring pathname; - struct lha *lha; const unsigned char *p; const char *signature; int err; @@ -485,7 +484,6 @@ archive_read_format_lha_read_header(struct archive_read *a, if (a->archive.archive_format_name == NULL) a->archive.archive_format_name = "lha"; - lha = (struct lha *)(a->format->data); lha->decompress_init = 0; lha->end_of_entry = 0; lha->end_of_entry_cleanup = 0; @@ -1451,7 +1449,7 @@ invalid: static int lha_end_of_entry(struct archive_read *a) { - struct lha *lha = (struct lha *)(a->format->data); + struct lha *lha = a->format->data; int r = ARCHIVE_EOF; if (!lha->end_of_entry_cleanup) { @@ -1472,7 +1470,7 @@ static int archive_read_format_lha_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct lha *lha = (struct lha *)(a->format->data); + struct lha *lha = a->format->data; int r; if (lha->entry_unconsumed) { @@ -1505,7 +1503,7 @@ static int lha_read_data_none(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct lha *lha = (struct lha *)(a->format->data); + struct lha *lha = a->format->data; ssize_t bytes_avail; if (lha->entry_bytes_remaining == 0) { @@ -1552,7 +1550,7 @@ static int lha_read_data_lzh(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct lha *lha = (struct lha *)(a->format->data); + struct lha *lha = a->format->data; ssize_t bytes_avail; int r; @@ -1642,11 +1640,9 @@ lha_read_data_lzh(struct archive_read *a, const void **buff, static int archive_read_format_lha_read_data_skip(struct archive_read *a) { - struct lha *lha; + struct lha *lha = a->format->data; int64_t bytes_skipped; - lha = (struct lha *)(a->format->data); - if (lha->entry_unconsumed) { /* Consume as much as the decompressor actually used. */ __archive_read_consume(a, lha->entry_unconsumed); @@ -1673,7 +1669,7 @@ archive_read_format_lha_read_data_skip(struct archive_read *a) static int archive_read_format_lha_cleanup(struct archive_read *a) { - struct lha *lha = (struct lha *)(a->format->data); + struct lha *lha = a->format->data; lzh_decode_free(&(lha->strm)); archive_string_free(&(lha->dirname)); @@ -1682,7 +1678,7 @@ archive_read_format_lha_cleanup(struct archive_read *a) archive_string_free(&(lha->gname)); archive_wstring_free(&(lha->ws)); free(lha); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index a8d1f4e63..dab580a30 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -161,9 +161,8 @@ static int archive_read_format_mtree_options(struct archive_read *a, const char *key, const char *val) { - struct mtree *mtree; + struct mtree *mtree = a->format->data; - mtree = (struct mtree *)(a->format->data); if (strcmp(key, "checkfs") == 0) { /* Allows to read information missing from the mtree from the file system */ if (val == NULL || val[0] == 0) { @@ -245,11 +244,9 @@ archive_read_support_format_mtree(struct archive *_a) static int cleanup(struct archive_read *a) { - struct mtree *mtree; + struct mtree *mtree = a->format->data; struct mtree_entry *p, *q; - mtree = (struct mtree *)(a->format->data); - /* Close any dangling file descriptor before freeing */ if (mtree->fd >= 0) { close(mtree->fd); @@ -270,7 +267,7 @@ cleanup(struct archive_read *a) free(mtree->buff); free(mtree); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } @@ -1069,12 +1066,10 @@ read_mtree(struct archive_read *a, struct mtree *mtree) static int read_header(struct archive_read *a, struct archive_entry *entry) { - struct mtree *mtree; + struct mtree *mtree = a->format->data; char *p; int r, use_next; - mtree = (struct mtree *)(a->format->data); - if (mtree->fd >= 0) { close(mtree->fd); mtree->fd = -1; @@ -1838,11 +1833,10 @@ static int read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { + struct mtree *mtree = a->format->data; size_t bytes_to_read; ssize_t bytes_read; - struct mtree *mtree; - mtree = (struct mtree *)(a->format->data); if (mtree->fd < 0) { *buff = NULL; *offset = 0; @@ -1883,9 +1877,8 @@ read_data(struct archive_read *a, const void **buff, size_t *size, static int skip(struct archive_read *a) { - struct mtree *mtree; + struct mtree *mtree = a->format->data; - mtree = (struct mtree *)(a->format->data); if (mtree->fd >= 0) { close(mtree->fd); mtree->fd = -1; diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c index 73a806798..2f253674b 100644 --- a/libarchive/archive_read_support_format_rar.c +++ b/libarchive/archive_read_support_format_rar.c @@ -498,7 +498,7 @@ static const uint32_t cache_masks[] = { static int rar_br_fillup(struct archive_read *a, struct rar_br *br) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; int n = CACHE_BITS - br->cache_avail; for (;;) { @@ -593,7 +593,7 @@ rar_br_fillup(struct archive_read *a, struct rar_br *br) static int rar_br_preparation(struct archive_read *a, struct rar_br *br) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; if (rar->bytes_remaining > 0) { br->next_in = rar_read_ahead(a, 1, &(br->avail_in)); @@ -708,7 +708,7 @@ static Byte ppmd_read(void *p) { struct archive_read *a = ((IByteIn*)p)->a; - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; struct rar_br *br = &(rar->br); Byte b; if (!rar_br_read_ahead(a, br, 8)) @@ -776,7 +776,7 @@ static int archive_read_format_rar_has_encrypted_entries(struct archive_read *_a) { if (_a && _a->format) { - struct rar * rar = (struct rar *)_a->format->data; + struct rar *rar = _a->format->data; if (rar) { return rar->has_encrypted_entries; } @@ -876,10 +876,9 @@ static int archive_read_format_rar_options(struct archive_read *a, const char *key, const char *val) { - struct rar *rar; + struct rar *rar = a->format->data; int ret = ARCHIVE_FAILED; - rar = (struct rar *)(a->format->data); if (strcmp(key, "hdrcharset") == 0) { if (val == NULL || val[0] == 0) archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, @@ -906,9 +905,9 @@ static int archive_read_format_rar_read_header(struct archive_read *a, struct archive_entry *entry) { + struct rar *rar = a->format->data; const void *h; const char *p; - struct rar *rar; int64_t skip; char head_type; int ret; @@ -919,8 +918,6 @@ archive_read_format_rar_read_header(struct archive_read *a, if (a->archive.archive_format_name == NULL) a->archive.archive_format_name = "RAR"; - rar = (struct rar *)(a->format->data); - /* * It should be sufficient to call archive_read_next_header() for * a reader to determine if an entry is encrypted or not. If the @@ -1099,7 +1096,7 @@ static int archive_read_format_rar_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; int ret; if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { @@ -1150,12 +1147,10 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff, static int archive_read_format_rar_read_data_skip(struct archive_read *a) { - struct rar *rar; + struct rar *rar = a->format->data; int64_t bytes_skipped; int ret; - rar = (struct rar *)(a->format->data); - if (rar->bytes_unconsumed > 0) { /* Consume as much as the decompressor actually used. */ __archive_read_consume(a, rar->bytes_unconsumed); @@ -1188,9 +1183,9 @@ static int64_t archive_read_format_rar_seek_data(struct archive_read *a, int64_t offset, int whence) { + struct rar *rar = a->format->data; int64_t client_offset, ret; size_t i; - struct rar *rar = (struct rar *)(a->format->data); if (rar->compression_method == COMPRESS_METHOD_STORE) { @@ -1341,9 +1336,8 @@ archive_read_format_rar_seek_data(struct archive_read *a, int64_t offset, static int archive_read_format_rar_cleanup(struct archive_read *a) { - struct rar *rar; + struct rar *rar = a->format->data; - rar = (struct rar *)(a->format->data); free_codes(a); clear_filters(&rar->filters); free(rar->filename); @@ -1353,7 +1347,7 @@ archive_read_format_rar_cleanup(struct archive_read *a) free(rar->lzss.window); __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context); free(rar); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } @@ -1361,9 +1355,9 @@ static int read_header(struct archive_read *a, struct archive_entry *entry, char head_type) { + struct rar *rar = a->format->data; const void *h; const char *p, *endp; - struct rar *rar; struct rar_header rar_header; struct rar_file_header file_header; int64_t header_size; @@ -1379,8 +1373,6 @@ read_header(struct archive_read *a, struct archive_entry *entry, char *newptr; size_t newsize; - rar = (struct rar *)(a->format->data); - /* Setup a string conversion object for non-rar-unicode filenames. */ sconv = rar->opt_sconv; if (sconv == NULL) { @@ -1963,12 +1955,11 @@ static int read_symlink_stored(struct archive_read *a, struct archive_entry *entry, struct archive_string_conv *sconv) { + struct rar *rar = a->format->data; const void *h; const char *p; - struct rar *rar; int ret = (ARCHIVE_OK); - rar = (struct rar *)(a->format->data); if ((uintmax_t)rar->packed_size > SIZE_MAX) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, @@ -2005,10 +1996,9 @@ static int read_data_stored(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct rar *rar; + struct rar *rar = a->format->data; ssize_t bytes_avail; - rar = (struct rar *)(a->format->data); if (rar->bytes_remaining == 0 && !(rar->main_flags & MHD_VOLUME && rar->file_flags & FHD_SPLIT_AFTER)) { @@ -2053,13 +2043,11 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, if (looper++ > MAX_COMPRESS_DEPTH) return (ARCHIVE_FAILED); - struct rar *rar; + struct rar *rar = a->format->data; int64_t start, end; size_t bs; int ret = (ARCHIVE_OK), sym, code, lzss_offset, length, i; - rar = (struct rar *)(a->format->data); - do { if (!rar->valid) return (ARCHIVE_FAILED); @@ -2304,11 +2292,11 @@ ending_block: static int parse_codes(struct archive_read *a) { + struct rar *rar = a->format->data; int i, j, val, n, r; unsigned char bitlengths[MAX_SYMBOLS], zerocount, ppmd_flags; unsigned int maxorder; struct huffman_code precode; - struct rar *rar = (struct rar *)(a->format->data); struct rar_br *br = &(rar->br); free_codes(a); @@ -2590,7 +2578,7 @@ truncated_data: static void free_codes(struct archive_read *a) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; free(rar->maincode.tree); free(rar->offsetcode.tree); free(rar->lowoffsetcode.tree); @@ -2609,10 +2597,10 @@ free_codes(struct archive_read *a) static int read_next_symbol(struct archive_read *a, struct huffman_code *code) { + struct rar *rar = a->format->data; unsigned char bit; unsigned int bits; int length, value, node; - struct rar *rar; struct rar_br *br; if (!code->table) @@ -2621,7 +2609,6 @@ read_next_symbol(struct archive_read *a, struct huffman_code *code) return -1; } - rar = (struct rar *)(a->format->data); br = &(rar->br); /* Look ahead (peek) at bits */ @@ -2964,9 +2951,9 @@ expand(struct archive_read *a, int64_t *end) static const unsigned char shortbits[] = { 2, 2, 3, 4, 5, 6, 6, 6 }; + struct rar *rar = a->format->data; int symbol, offs, len, offsindex, lensymbol, i, offssymbol, lowoffsetsymbol; unsigned char newfile; - struct rar *rar = (struct rar *)(a->format->data); struct rar_br *br = &(rar->br); if (rar->filters.filterstart < *end) @@ -3154,8 +3141,8 @@ static int copy_from_lzss_window(struct archive_read *a, uint8_t *buffer, int64_t startpos, int length) { + struct rar *rar = a->format->data; int windowoffs, firstpart; - struct rar *rar = (struct rar *)(a->format->data); windowoffs = lzss_offset_for_position(&rar->lzss, startpos); firstpart = lzss_size(&rar->lzss) - windowoffs; @@ -3182,8 +3169,8 @@ static int copy_from_lzss_window_to_unp(struct archive_read *a, const void **buffer, int64_t startpos, size_t length) { + struct rar *rar = a->format->data; int windowoffs, firstpart; - struct rar *rar = (struct rar *)(a->format->data); if (length > rar->unp_buffer_size) { @@ -3239,7 +3226,7 @@ fatal: static const void * rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; const void *h; int ret; @@ -3276,7 +3263,7 @@ again: static int parse_filter(struct archive_read *a, const uint8_t *bytes, uint16_t length, uint8_t flags) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; struct rar_filters *filters = &rar->filters; struct memory_bit_reader br = { 0 }; @@ -3444,7 +3431,7 @@ create_filter(struct rar_program_code *prog, const uint8_t *globaldata, uint32_t static int run_filters(struct archive_read *a) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; struct rar_filters *filters = &rar->filters; struct rar_filter *filter = filters->stack; struct rar_filter *f; @@ -3664,7 +3651,7 @@ membr_fill(struct memory_bit_reader *br, int bits) static int read_filter(struct archive_read *a, int64_t *end) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; uint8_t flags, val, *code; uint16_t length, i; @@ -3917,7 +3904,7 @@ execute_filter(struct archive_read *a, struct rar_filter *filter, struct rar_vir static int rar_decode_byte(struct archive_read *a, uint8_t *byte) { - struct rar *rar = (struct rar *)(a->format->data); + struct rar *rar = a->format->data; struct rar_br *br = &(rar->br); if (!rar_br_read_ahead(a, br, 8)) return 0; diff --git a/libarchive/archive_read_support_format_rar5.c b/libarchive/archive_read_support_format_rar5.c index 1fe7cd86a..517054e4e 100644 --- a/libarchive/archive_read_support_format_rar5.c +++ b/libarchive/archive_read_support_format_rar5.c @@ -514,10 +514,6 @@ uint8_t bf_is_last_block(const struct compressed_block_header* hdr) { return (hdr->block_flags_u8 >> 6) & 1; } -static inline struct rar5* get_context(struct archive_read* a) { - return (struct rar5*) a->format->data; -} - /* Convenience functions used by filter implementations. */ static void circular_memcpy(uint8_t* dst, uint8_t* window, const ssize_t mask, int64_t start, int64_t end) @@ -666,8 +662,8 @@ static int run_arm_filter(struct rar5* rar, struct filter_info* flt) { } static int run_filter(struct archive_read* a, struct filter_info* flt) { + struct rar5 *rar = a->format->data; int ret; - struct rar5* rar = get_context(a); clear_data_ready_stack(rar); free(rar->cstate.filtered_buf); @@ -776,8 +772,8 @@ static void push_window_data(struct archive_read* a, struct rar5* rar, } static int apply_filters(struct archive_read* a) { + struct rar5 *rar = a->format->data; struct filter_info* flt; - struct rar5* rar = get_context(a); int ret; rar->cstate.all_filters_applied = 0; @@ -2186,7 +2182,7 @@ static int process_head_main(struct archive_read* a, struct rar5* rar, } static int skip_unprocessed_bytes(struct archive_read* a) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; int ret; if(rar->file.bytes_remaining) { @@ -2298,7 +2294,7 @@ static int process_base_block(struct archive_read* a, { const size_t SMALLEST_RAR5_BLOCK_SIZE = 3; - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; uint32_t hdr_crc, computed_crc; size_t raw_hdr_size = 0, hdr_size_len, hdr_size; size_t header_id = 0; @@ -2474,8 +2470,8 @@ static int process_base_block(struct archive_read* a, } static int skip_base_block(struct archive_read* a) { + struct rar5 *rar = a->format->data; int ret; - struct rar5* rar = get_context(a); /* Create a new local archive_entry structure that will be operated on * by header reader; operations on this archive_entry will be discarded. @@ -2559,7 +2555,7 @@ fatal: static int rar5_read_header(struct archive_read *a, struct archive_entry *entry) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; int ret; /* @@ -2734,10 +2730,10 @@ static int create_decode_tables(uint8_t* bit_length, static int decode_number(struct archive_read* a, struct decode_table* table, const uint8_t* p, uint16_t* num) { + struct rar5 *rar = a->format->data; int i, bits, dist, ret; uint16_t bitfield; uint32_t pos; - struct rar5* rar = get_context(a); if(ARCHIVE_OK != (ret = read_bits_16(a, rar, p, &bitfield))) { return ret; @@ -3064,10 +3060,10 @@ static int is_valid_filter_block_start(struct rar5* rar, /* The function will create a new filter, read its parameters from the input * stream and add it to the filter collection. */ static int parse_filter(struct archive_read* ar, const uint8_t* p) { + struct rar5 *rar = ar->format->data; uint32_t block_start, block_length; uint16_t filter_type; struct filter_info* filt = NULL; - struct rar5* rar = get_context(ar); int ret; /* Read the parameters from the input stream. */ @@ -3152,7 +3148,7 @@ static int decode_code_length(struct archive_read* a, struct rar5* rar, } static int copy_string(struct archive_read* a, int len, int dist) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; const ssize_t cmask = rar->cstate.window_mask; const uint64_t write_ptr = rar->cstate.write_ptr + rar->cstate.solid_offset; @@ -3187,7 +3183,7 @@ static int copy_string(struct archive_read* a, int len, int dist) { } static int do_uncompress_block(struct archive_read* a, const uint8_t* p) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; uint16_t num; int ret; @@ -3464,8 +3460,8 @@ static int scan_for_signature(struct archive_read* a) { /* This function will switch the multivolume archive file to another file, * i.e. from part03 to part 04. */ static int advance_multivolume(struct archive_read* a) { + struct rar5 *rar = a->format->data; int lret; - struct rar5* rar = get_context(a); /* A small state machine that will skip unnecessary data, needed to * switch from one multivolume to another. Such skipping is needed if @@ -3541,7 +3537,7 @@ static int advance_multivolume(struct archive_read* a) { static int merge_block(struct archive_read* a, ssize_t block_size, const uint8_t** p) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; ssize_t cur_block_size, partial_offset = 0; const uint8_t* lp; int ret; @@ -3659,8 +3655,8 @@ static int merge_block(struct archive_read* a, ssize_t block_size, } static int process_block(struct archive_read* a) { + struct rar5 *rar = a->format->data; const uint8_t* p; - struct rar5* rar = get_context(a); int ret; /* If we don't have any data to be processed, this most probably means @@ -3938,7 +3934,7 @@ static int push_data_ready(struct archive_read* a, struct rar5* rar, * */ static int do_uncompress_file(struct archive_read* a) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; int ret; int64_t max_end_pos; @@ -4161,8 +4157,8 @@ static int do_unpack(struct archive_read* a, struct rar5* rar, } static int verify_checksums(struct archive_read* a) { + struct rar5 *rar = a->format->data; int verify_crc; - struct rar5* rar = get_context(a); /* Check checksums only when actually unpacking the data. There's no * need to calculate checksum when we're skipping data in solid archives @@ -4276,8 +4272,8 @@ static void rar5_signature(char *buf) { static int rar5_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { + struct rar5 *rar = a->format->data; int ret; - struct rar5* rar = get_context(a); if (size) *size = 0; @@ -4341,7 +4337,7 @@ static int rar5_read_data(struct archive_read *a, const void **buff, } static int rar5_read_data_skip(struct archive_read *a) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; if(rar->main.solid && (rar->cstate.data_encrypted == 0)) { /* In solid archives, instead of skipping the data, we need to @@ -4407,7 +4403,7 @@ static int64_t rar5_seek_data(struct archive_read *a, int64_t offset, } static int rar5_cleanup(struct archive_read *a) { - struct rar5* rar = get_context(a); + struct rar5 *rar = a->format->data; free(rar->cstate.window_buf); free(rar->cstate.filtered_buf); @@ -4432,7 +4428,7 @@ static int rar5_capabilities(struct archive_read * a) { static int rar5_has_encrypted_entries(struct archive_read *_a) { if (_a && _a->format) { - struct rar5 *rar = (struct rar5 *)_a->format->data; + struct rar5 *rar = _a->format->data; if (rar) { return rar->has_encrypted_entries; } diff --git a/libarchive/archive_read_support_format_raw.c b/libarchive/archive_read_support_format_raw.c index f284d9bcd..b49c15fd8 100644 --- a/libarchive/archive_read_support_format_raw.c +++ b/libarchive/archive_read_support_format_raw.c @@ -55,8 +55,8 @@ static int archive_read_format_raw_read_header(struct archive_read *, int archive_read_support_format_raw(struct archive *_a) { - struct raw_info *info; struct archive_read *a = (struct archive_read *)_a; + struct raw_info *info; int r; archive_check_magic(_a, ARCHIVE_READ_MAGIC, @@ -108,9 +108,8 @@ static int archive_read_format_raw_read_header(struct archive_read *a, struct archive_entry *entry) { - struct raw_info *info; + struct raw_info *info = a->format->data; - info = (struct raw_info *)(a->format->data); if (info->end_of_file) return (ARCHIVE_EOF); @@ -129,11 +128,9 @@ static int archive_read_format_raw_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct raw_info *info; + struct raw_info *info = a->format->data; ssize_t avail; - info = (struct raw_info *)(a->format->data); - /* Consume the bytes we read last time. */ if (info->unconsumed) { __archive_read_consume(a, info->unconsumed); @@ -175,7 +172,7 @@ archive_read_format_raw_read_data(struct archive_read *a, static int archive_read_format_raw_read_data_skip(struct archive_read *a) { - struct raw_info *info = (struct raw_info *)(a->format->data); + struct raw_info *info = a->format->data; /* Consume the bytes we read last time. */ if (info->unconsumed) { @@ -189,9 +186,8 @@ archive_read_format_raw_read_data_skip(struct archive_read *a) static int archive_read_format_raw_cleanup(struct archive_read *a) { - struct raw_info *info; + struct raw_info *info = a->format->data; - info = (struct raw_info *)(a->format->data); free(info); a->format->data = NULL; return (ARCHIVE_OK); diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c index 884343223..a51ba298e 100644 --- a/libarchive/archive_read_support_format_tar.c +++ b/libarchive/archive_read_support_format_tar.c @@ -300,9 +300,8 @@ archive_read_support_format_tar(struct archive *_a) static int archive_read_format_tar_cleanup(struct archive_read *a) { - struct tar *tar; + struct tar *tar = a->format->data; - tar = (struct tar *)(a->format->data); gnu_clear_sparse_list(tar); archive_string_free(&tar->entry_pathname); archive_string_free(&tar->entry_pathname_override); @@ -312,7 +311,7 @@ archive_read_format_tar_cleanup(struct archive_read *a) archive_string_free(&tar->line); archive_string_free(&tar->localname); free(tar); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } @@ -439,10 +438,9 @@ static int archive_read_format_tar_options(struct archive_read *a, const char *key, const char *val) { - struct tar *tar; + struct tar *tar = a->format->data; int ret = ARCHIVE_FAILED; - tar = (struct tar *)(a->format->data); if (strcmp(key, "compat-2x") == 0) { /* Handle UTF-8 filenames as libarchive 2.x */ tar->compat_2x = (val != NULL && val[0] != 0); @@ -525,15 +523,13 @@ archive_read_format_tar_read_header(struct archive_read *a, * probably not worthwhile just to support the relatively * obscure tar->cpio conversion case. */ - struct tar *tar; + struct tar *tar = a->format->data; const char *p; const wchar_t *wp; int r; size_t l; int64_t unconsumed = 0; - tar = (struct tar *)(a->format->data); - /* Assign default device/inode values. */ archive_entry_set_dev(entry, 1 + tar->default_dev); /* Don't use zero. */ archive_entry_set_ino(entry, ++tar->default_inode); /* Don't use zero. */ @@ -609,12 +605,10 @@ static int archive_read_format_tar_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { + struct tar *tar = a->format->data; ssize_t bytes_read; - struct tar *tar; struct sparse_block *p; - tar = (struct tar *)(a->format->data); - for (;;) { /* Remove exhausted entries from sparse list. */ while (tar->sparse_list != NULL && @@ -673,10 +667,8 @@ archive_read_format_tar_read_data(struct archive_read *a, static int archive_read_format_tar_skip(struct archive_read *a) { + struct tar *tar = a->format->data; int64_t request; - struct tar* tar; - - tar = (struct tar *)(a->format->data); request = tar->entry_bytes_remaining + tar->entry_padding + tar->entry_bytes_unconsumed; diff --git a/libarchive/archive_read_support_format_xar.c b/libarchive/archive_read_support_format_xar.c index 568b2f5aa..cd61342ab 100644 --- a/libarchive/archive_read_support_format_xar.c +++ b/libarchive/archive_read_support_format_xar.c @@ -536,7 +536,7 @@ xar_bid(struct archive_read *a, int best_bid) static int read_toc(struct archive_read *a) { - struct xar *xar; + struct xar *xar = a->format->data; struct xar_file *file; const unsigned char *b; uint64_t toc_compressed_size; @@ -545,8 +545,6 @@ read_toc(struct archive_read *a) ssize_t bytes; int r; - xar = (struct xar *)(a->format->data); - /* * Read xar header. */ @@ -674,12 +672,11 @@ read_toc(struct archive_read *a) static int xar_read_header(struct archive_read *a, struct archive_entry *entry) { - struct xar *xar; + struct xar *xar = a->format->data; struct xar_file *file; struct xattr *xattr; int r; - xar = (struct xar *)(a->format->data); r = ARCHIVE_OK; if (xar->offset == 0) { @@ -878,12 +875,10 @@ static int xar_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct xar *xar; + struct xar *xar = a->format->data; size_t used = 0; int r; - xar = (struct xar *)(a->format->data); - if (xar->entry_unconsumed) { __archive_read_consume(a, xar->entry_unconsumed); xar->entry_unconsumed = 0; @@ -941,10 +936,9 @@ abort_read_data: static int xar_read_data_skip(struct archive_read *a) { - struct xar *xar; + struct xar *xar = a->format->data; int64_t bytes_skipped; - xar = (struct xar *)(a->format->data); if (xar->end_of_file) return (ARCHIVE_EOF); bytes_skipped = __archive_read_consume(a, xar->entry_remaining + @@ -959,12 +953,11 @@ xar_read_data_skip(struct archive_read *a) static int xar_cleanup(struct archive_read *a) { - struct xar *xar; + struct xar *xar = a->format->data; struct hdlink *hdlink; size_t i; int r; - xar = (struct xar *)(a->format->data); checksum_cleanup(a); r = decompression_cleanup(a); hdlink = xar->hdlink_list; @@ -994,9 +987,8 @@ xar_cleanup(struct archive_read *a) static int move_reading_point(struct archive_read *a, uint64_t offset) { - struct xar *xar; + struct xar *xar = a->format->data; - xar = (struct xar *)(a->format->data); if (xar->offset - xar->h_base != offset) { /* Seek forward to the start of file contents. */ int64_t step; @@ -1398,9 +1390,8 @@ _checksum_final(struct chksumwork *sumwrk, const void *val, size_t len) static void checksum_init(struct archive_read *a, int a_sum_alg, int e_sum_alg) { - struct xar *xar; + struct xar *xar = a->format->data; - xar = (struct xar *)(a->format->data); _checksum_init(&(xar->a_sumwrk), a_sum_alg); _checksum_init(&(xar->e_sumwrk), e_sum_alg); } @@ -1409,9 +1400,8 @@ static void checksum_update(struct archive_read *a, const void *abuff, size_t asize, const void *ebuff, size_t esize) { - struct xar *xar; + struct xar *xar = a->format->data; - xar = (struct xar *)(a->format->data); _checksum_update(&(xar->a_sumwrk), abuff, asize); _checksum_update(&(xar->e_sumwrk), ebuff, esize); } @@ -1420,10 +1410,9 @@ static int checksum_final(struct archive_read *a, const void *a_sum_val, size_t a_sum_len, const void *e_sum_val, size_t e_sum_len) { - struct xar *xar; + struct xar *xar = a->format->data; int r; - xar = (struct xar *)(a->format->data); r = _checksum_final(&(xar->a_sumwrk), a_sum_val, a_sum_len); if (r == ARCHIVE_OK) r = _checksum_final(&(xar->e_sumwrk), e_sum_val, e_sum_len); @@ -1436,11 +1425,10 @@ checksum_final(struct archive_read *a, const void *a_sum_val, static int decompression_init(struct archive_read *a, enum enctype encoding) { - struct xar *xar; + struct xar *xar = a->format->data; const char *detail; int r; - xar = (struct xar *)(a->format->data); xar->rd_encoding = encoding; switch (encoding) { case NONE: @@ -1576,12 +1564,11 @@ static int decompress(struct archive_read *a, const void **buff, size_t *outbytes, const void *b, size_t *used) { - struct xar *xar; + struct xar *xar = a->format->data; void *outbuff; size_t avail_in, avail_out; int r; - xar = (struct xar *)(a->format->data); avail_in = *used; outbuff = (void *)(uintptr_t)*buff; if (outbuff == NULL) { @@ -1704,10 +1691,9 @@ decompress(struct archive_read *a, const void **buff, size_t *outbytes, static int decompression_cleanup(struct archive_read *a) { - struct xar *xar; + struct xar *xar = a->format->data; int r; - xar = (struct xar *)(a->format->data); r = ARCHIVE_OK; if (xar->stream_valid) { if (inflateEnd(&(xar->stream)) != Z_OK) { @@ -1736,9 +1722,7 @@ decompression_cleanup(struct archive_read *a) static void checksum_cleanup(struct archive_read *a) { - struct xar *xar; - - xar = (struct xar *)(a->format->data); + struct xar *xar = a->format->data; _checksum_final(&(xar->a_sumwrk), NULL, 0); _checksum_final(&(xar->e_sumwrk), NULL, 0); @@ -1960,11 +1944,9 @@ unknowntag_end(struct xar *xar, const char *name) static int xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list) { - struct xar *xar; + struct xar *xar = a->format->data; struct xmlattr *attr; - xar = (struct xar *)(a->format->data); - #if DEBUG fprintf(stderr, "xml_sta:[%s]\n", name); for (attr = list->first; attr != NULL; attr = attr->next) @@ -2256,11 +2238,8 @@ xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list) static void xml_end(void *userData, const char *name) { - struct archive_read *a; - struct xar *xar; - - a = (struct archive_read *)userData; - xar = (struct xar *)(a->format->data); + struct archive_read *a = (struct archive_read *)userData; + struct xar *xar = a->format->data; #if DEBUG fprintf(stderr, "xml_end:[%s]\n", name); @@ -2682,14 +2661,11 @@ is_string(const char *known, const char *data, size_t len) static int xml_data(void *userData, const char *s, size_t len) { + struct archive_read *a = (struct archive_read *)userData; + struct xar *xar = a->format->data; uint64_t val; - struct archive_read *a; - struct xar *xar; int r; - a = (struct archive_read *)userData; - xar = (struct xar *)(a->format->data); - #if DEBUG { char buff[1024]; @@ -3169,16 +3145,13 @@ xml2_xmlattr_setup(struct archive_read *a, static int xml2_read_cb(void *context, char *buffer, int len) { - struct archive_read *a; - struct xar *xar; + struct archive_read *a = (struct archive_read *)context; + struct xar *xar = a->format->data; const void *d; size_t outbytes; size_t used = 0; int r; - a = (struct archive_read *)context; - xar = (struct xar *)(a->format->data); - if (xar->toc_remaining <= 0) return (0); d = buffer; @@ -3207,10 +3180,9 @@ static void xml2_error_hdr(void *arg, const char *msg, xmlParserSeverities severity, xmlTextReaderLocatorPtr locator) { - struct archive_read *a; + struct archive_read *a = (struct archive_read *)arg; (void)locator; /* UNUSED */ - a = (struct archive_read *)arg; switch (severity) { case XML_PARSER_SEVERITY_VALIDITY_WARNING: case XML_PARSER_SEVERITY_WARNING: @@ -3360,15 +3332,13 @@ expat_data_cb(void *userData, const XML_Char *s, int len) static int expat_read_toc(struct archive_read *a) { - struct xar *xar; + struct xar *xar = a->format->data; XML_Parser parser; struct expat_userData ud; ud.state = ARCHIVE_OK; ud.archive = a; - xar = (struct xar *)(a->format->data); - /* Initialize XML Parser library. */ parser = XML_ParserCreate(NULL); if (parser == NULL) { @@ -3452,16 +3422,13 @@ static HRESULT STDMETHODCALLTYPE asaRead(ISequentialStream *this, void *pv, ULONG cb, ULONG *pcbRead) { struct ArchiveStreamAdapter *asa = (struct ArchiveStreamAdapter *)this; - struct archive_read *a; - struct xar *xar; + struct archive_read *a = asa->a; + struct xar *xar = a->format->data; const void *d = pv; size_t outbytes = cb; size_t used = 0; int r; - a = asa->a; - xar = (struct xar *)(a->format->data); - *pcbRead = 0; if (xar->toc_remaining <= 0) diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c index 081420e31..4148c4c90 100644 --- a/libarchive/archive_read_support_format_zip.c +++ b/libarchive/archive_read_support_format_zip.c @@ -291,7 +291,7 @@ static Byte ppmd_read(void* p) { /* Get the handle to current decompression context. */ struct archive_read *a = ((IByteIn*)p)->a; - struct zip *zip = (struct zip*) a->format->data; + struct zip *zip = a->format->data; /* Fetch next byte. */ const uint8_t* data = __archive_read_ahead(a, 1, NULL); @@ -437,7 +437,7 @@ static int zipx_read_header_and_decrypt(struct archive_read *a, const void **buf, size_t in_len, size_t *out_len, size_t *consumed) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; const void *raw; ssize_t bytes_avail; size_t to_decrypt; @@ -656,8 +656,8 @@ static int process_extra(struct archive_read *a, struct archive_entry *entry, const char *p, size_t extra_length, struct zip_entry* zip_entry) { + struct zip *zip = a->format->data; unsigned offset = 0; - struct zip *zip = (struct zip *)(a->format->data); if (extra_length == 0) { return ARCHIVE_OK; @@ -1483,7 +1483,7 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, static int check_authentication_code(struct archive_read *a, const void *_p) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; /* Check authentication code. */ if (zip->hctx_valid) { @@ -1807,7 +1807,7 @@ static int zip_read_data_none(struct archive_read *a, const void **_buff, size_t *size, int64_t *offset) { - struct zip *zip; + struct zip *zip = a->format->data; const char *buff; ssize_t bytes_avail; ssize_t trailing_extra; @@ -1815,7 +1815,6 @@ zip_read_data_none(struct archive_read *a, const void **_buff, (void)offset; /* UNUSED */ - zip = (struct zip *)(a->format->data); trailing_extra = zip->hctx_valid ? AUTH_CODE_SIZE : 0; if (zip->entry->zip_flags & ZIP_LENGTH_AT_END) { @@ -2126,7 +2125,7 @@ static int zip_read_data_zipx_xz(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct zip* zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; int ret; lzma_ret lz_ret; const void* compressed_buf; @@ -2226,7 +2225,7 @@ static int zip_read_data_zipx_lzma_alone(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct zip* zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; int ret; lzma_ret lz_ret; const void* compressed_buf; @@ -2496,7 +2495,7 @@ static int zip_read_data_zipx_ppmd(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct zip* zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; int ret; size_t consumed_bytes = 0; @@ -2615,7 +2614,7 @@ static int zip_read_data_zipx_bzip2(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; ssize_t bytes_avail = 0, to_consume; const void *compressed_buff; const void *sp; @@ -2766,7 +2765,7 @@ static int zip_read_data_zipx_zstd(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; ssize_t bytes_avail = 0, to_consume; const void *compressed_buff; const void *sp; @@ -2888,7 +2887,7 @@ static int zip_read_data_deflate(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - struct zip *zip; + struct zip *zip = a->format->data; ssize_t bytes_avail, to_consume = 0; const void *compressed_buff; const void *sp; @@ -2896,8 +2895,6 @@ zip_read_data_deflate(struct archive_read *a, const void **buff, (void)offset; /* UNUSED */ - zip = (struct zip *)(a->format->data); - /* If the buffer hasn't been allocated, allocate it now. */ if (zip->uncompressed_buffer == NULL) { zip->uncompressed_buffer_size = 256 * 1024; @@ -2990,7 +2987,7 @@ zip_read_data_deflate(struct archive_read *a, const void **buff, static int read_decryption_header(struct archive_read *a) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; const char *p; unsigned int remaining_size; unsigned int ts; @@ -3184,7 +3181,7 @@ nomem: static int zip_alloc_decryption_buffer(struct archive_read *a) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; size_t bs = 256 * 1024; if (zip->decrypted_buffer == NULL) { @@ -3203,7 +3200,7 @@ zip_alloc_decryption_buffer(struct archive_read *a) static int init_traditional_PKWARE_decryption(struct archive_read *a) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; const void *p; int retry; int r; @@ -3275,7 +3272,7 @@ init_traditional_PKWARE_decryption(struct archive_read *a) static int init_WinZip_AES_decryption(struct archive_read *a) { - struct zip *zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; const void *p; const uint8_t *pv; size_t key_len, salt_len; @@ -3369,8 +3366,8 @@ static int archive_read_format_zip_read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { + struct zip *zip = a->format->data; int r; - struct zip *zip = (struct zip *)(a->format->data); if (zip->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) { @@ -3514,11 +3511,9 @@ archive_read_format_zip_read_data(struct archive_read *a, static int archive_read_format_zip_cleanup(struct archive_read *a) { - struct zip *zip; + struct zip *zip = a->format->data; struct zip_entry *zip_entry, *next_zip_entry; - zip = (struct zip *)(a->format->data); - #ifdef HAVE_ZLIB_H if (zip->stream_valid) inflateEnd(&zip->stream); @@ -3566,7 +3561,7 @@ archive_read_format_zip_cleanup(struct archive_read *a) free(zip->v_data); archive_string_free(&zip->format_name); free(zip); - (a->format->data) = NULL; + a->format->data = NULL; return (ARCHIVE_OK); } @@ -3574,7 +3569,7 @@ static int archive_read_format_zip_has_encrypted_entries(struct archive_read *_a) { if (_a && _a->format) { - struct zip * zip = (struct zip *)_a->format->data; + struct zip *zip = _a->format->data; if (zip) { return zip->has_encrypted_entries; } @@ -3586,10 +3581,9 @@ static int archive_read_format_zip_options(struct archive_read *a, const char *key, const char *val) { - struct zip *zip; + struct zip *zip = a->format->data; int ret = ARCHIVE_FAILED; - zip = (struct zip *)(a->format->data); if (strcmp(key, "compat-2x") == 0) { /* Handle filenames as libarchive 2.x */ zip->init_default_conversion = (val != NULL) ? 1 : 0; @@ -3696,14 +3690,12 @@ static int archive_read_format_zip_streamable_read_header(struct archive_read *a, struct archive_entry *entry) { - struct zip *zip; + struct zip *zip = a->format->data; a->archive.archive_format = ARCHIVE_FORMAT_ZIP; if (a->archive.archive_format_name == NULL) a->archive.archive_format_name = "ZIP"; - zip = (struct zip *)(a->format->data); - /* * It should be sufficient to call archive_read_next_header() for * a reader to determine if an entry is encrypted or not. If the @@ -3789,10 +3781,9 @@ archive_read_format_zip_streamable_read_header(struct archive_read *a, static int archive_read_format_zip_read_data_skip_streamable(struct archive_read *a) { - struct zip *zip; + struct zip *zip = a->format->data; int64_t bytes_skipped; - zip = (struct zip *)(a->format->data); bytes_skipped = __archive_read_consume(a, zip->unconsumed); zip->unconsumed = 0; if (bytes_skipped < 0) @@ -4034,7 +4025,7 @@ read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p) static int archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid) { - struct zip *zip = (struct zip *)a->format->data; + struct zip *zip = a->format->data; int64_t file_size, current_offset; const char *p; int i, tail; @@ -4432,7 +4423,7 @@ static int zip_read_mac_metadata(struct archive_read *a, struct archive_entry *entry, struct zip_entry *rsrc) { - struct zip *zip = (struct zip *)a->format->data; + struct zip *zip = a->format->data; unsigned char *metadata, *mp; int64_t offset = archive_filter_bytes(&a->archive, 0); size_t remaining_bytes, metadata_bytes; @@ -4583,7 +4574,7 @@ static int archive_read_format_zip_seekable_read_header(struct archive_read *a, struct archive_entry *entry) { - struct zip *zip = (struct zip *)a->format->data; + struct zip *zip = a->format->data; struct zip_entry *rsrc; int64_t offset; int r, ret = ARCHIVE_OK; @@ -4663,8 +4654,7 @@ archive_read_format_zip_seekable_read_header(struct archive_read *a, static int archive_read_format_zip_read_data_skip_seekable(struct archive_read *a) { - struct zip *zip; - zip = (struct zip *)(a->format->data); + struct zip *zip = a->format->data; zip->unconsumed = 0; return (ARCHIVE_OK); diff --git a/libarchive/archive_write_set_format_7zip.c b/libarchive/archive_write_set_format_7zip.c index 4a3fd7656..b5cc8e500 100644 --- a/libarchive/archive_write_set_format_7zip.c +++ b/libarchive/archive_write_set_format_7zip.c @@ -412,9 +412,7 @@ archive_write_set_format_7zip(struct archive *_a) static int _7z_options(struct archive_write *a, const char *key, const char *value) { - struct _7zip *zip; - - zip = (struct _7zip *)a->format_data; + struct _7zip *zip = a->format_data; if (strcmp(key, "compression") == 0) { const char *name = NULL; @@ -556,11 +554,10 @@ _7z_options(struct archive_write *a, const char *key, const char *value) static int _7z_write_header(struct archive_write *a, struct archive_entry *entry) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; struct file *file; int r; - zip = (struct _7zip *)a->format_data; zip->cur_file = NULL; zip->entry_bytes_remaining = 0; @@ -664,12 +661,10 @@ _7z_write_header(struct archive_write *a, struct archive_entry *entry) static int write_to_temp(struct archive_write *a, const void *buff, size_t s) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; const unsigned char *p; ssize_t ws; - zip = (struct _7zip *)a->format_data; - /* * Open a temporary file. */ @@ -702,7 +697,7 @@ static ssize_t compress_out(struct archive_write *a, const void *buff, size_t s, enum la_zaction run) { - struct _7zip *zip = (struct _7zip *)a->format_data; + struct _7zip *zip = a->format_data; int r; if (run == ARCHIVE_Z_FINISH && zip->stream.total_in == 0 && s == 0) @@ -748,11 +743,9 @@ compress_out(struct archive_write *a, const void *buff, size_t s, static ssize_t _7z_write_data(struct archive_write *a, const void *buff, size_t s) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; ssize_t bytes; - zip = (struct _7zip *)a->format_data; - if (s > zip->entry_bytes_remaining) s = (size_t)zip->entry_bytes_remaining; if (s == 0 || zip->cur_file == NULL) @@ -768,11 +761,10 @@ _7z_write_data(struct archive_write *a, const void *buff, size_t s) static int _7z_finish_entry(struct archive_write *a) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; size_t s; ssize_t r; - zip = (struct _7zip *)a->format_data; if (zip->cur_file == NULL) return (ARCHIVE_OK); @@ -793,11 +785,10 @@ _7z_finish_entry(struct archive_write *a) static int flush_wbuff(struct archive_write *a) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; int r; size_t s; - zip = (struct _7zip *)a->format_data; s = sizeof(zip->wbuff) - zip->wbuff_remaining; r = __archive_write_output(a, zip->wbuff, s); if (r != ARCHIVE_OK) @@ -809,10 +800,9 @@ flush_wbuff(struct archive_write *a) static int copy_out(struct archive_write *a, uint64_t offset, uint64_t length) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; int r; - zip = (struct _7zip *)a->format_data; if (zip->temp_offset > 0 && lseek(zip->temp_fd, offset, SEEK_SET) < 0) { archive_set_error(&(a->archive), errno, "lseek failed"); @@ -855,15 +845,13 @@ copy_out(struct archive_write *a, uint64_t offset, uint64_t length) static int _7z_close(struct archive_write *a) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; unsigned char *wb; uint64_t header_offset, header_size, header_unpacksize; uint64_t length; uint32_t header_crc32; int r; - zip = (struct _7zip *)a->format_data; - if (zip->total_number_entry > 0) { struct archive_rb_node *n; uint64_t data_offset, data_size, data_unpacksize; @@ -1028,7 +1016,7 @@ enc_uint64(struct archive_write *a, uint64_t val) static int make_substreamsInfo(struct archive_write *a, struct coder *coders) { - struct _7zip *zip = (struct _7zip *)a->format_data; + struct _7zip *zip = a->format_data; struct file *file; int r; @@ -1104,7 +1092,7 @@ make_streamsInfo(struct archive_write *a, uint64_t offset, uint64_t pack_size, uint64_t unpack_size, int num_coder, struct coder *coders, int substrm, uint32_t header_crc) { - struct _7zip *zip = (struct _7zip *)a->format_data; + struct _7zip *zip = a->format_data; uint8_t codec_buff[8]; int numFolders, fi; int codec_size; @@ -1296,8 +1284,8 @@ make_streamsInfo(struct archive_write *a, uint64_t offset, uint64_t pack_size, static int make_time(struct archive_write *a, uint8_t type, unsigned flg, int ti) { + struct _7zip *zip = a->format_data; uint8_t filetime[8]; - struct _7zip *zip = (struct _7zip *)a->format_data; struct file *file; int r; uint8_t b, mask; @@ -1385,7 +1373,7 @@ static int make_header(struct archive_write *a, uint64_t offset, uint64_t pack_size, uint64_t unpack_size, int codernum, struct coder *coders) { - struct _7zip *zip = (struct _7zip *)a->format_data; + struct _7zip *zip = a->format_data; struct file *file; int r; uint8_t b, mask; @@ -1593,7 +1581,7 @@ make_header(struct archive_write *a, uint64_t offset, uint64_t pack_size, static int _7z_free(struct archive_write *a) { - struct _7zip *zip = (struct _7zip *)a->format_data; + struct _7zip *zip = a->format_data; /* Close the temporary file. */ if (zip->temp_fd >= 0) @@ -1631,13 +1619,12 @@ static int file_new(struct archive_write *a, struct archive_entry *entry, struct file **newfile) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; struct file *file; const char *u16; size_t u16len; int ret = ARCHIVE_OK; - zip = (struct _7zip *)a->format_data; *newfile = NULL; file = calloc(1, sizeof(*file)); @@ -2255,7 +2242,7 @@ static void ppmd_write(void *p, Byte b) { struct archive_write *a = ((IByteOut *)p)->a; - struct _7zip *zip = (struct _7zip *)(a->format_data); + struct _7zip *zip = a->format_data; struct la_zstream *lastrm = &(zip->stream); struct ppmd_stream *strm; @@ -2512,10 +2499,9 @@ static int _7z_compression_init_encoder(struct archive_write *a, unsigned compression, int compression_level) { - struct _7zip *zip; + struct _7zip *zip = a->format_data; int r; - zip = (struct _7zip *)a->format_data; switch (compression) { case _7Z_DEFLATE: r = compression_init_encoder_deflate( diff --git a/libarchive/archive_write_set_format_ar.c b/libarchive/archive_write_set_format_ar.c index 57046bfb6..82eff3dd1 100644 --- a/libarchive/archive_write_set_format_ar.c +++ b/libarchive/archive_write_set_format_ar.c @@ -147,7 +147,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) int ret, append_fn; char buff[60]; char *ss; - struct ar_w *ar; + struct ar_w *ar = a->format_data; struct archive_string se; const char *pathname; const char *filename; @@ -155,7 +155,6 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) int64_t size; append_fn = 0; - ar = (struct ar_w *)a->format_data; ar->is_strtab = 0; filename = NULL; filename_length = 0; @@ -364,10 +363,9 @@ size: static ssize_t archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) { - struct ar_w *ar; + struct ar_w *ar = a->format_data; int ret; - ar = (struct ar_w *)a->format_data; if (s > ar->entry_bytes_remaining) s = (size_t)ar->entry_bytes_remaining; @@ -400,9 +398,7 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) static int archive_write_ar_free(struct archive_write *a) { - struct ar_w *ar; - - ar = (struct ar_w *)a->format_data; + struct ar_w *ar = a->format_data; if (ar == NULL) return (ARCHIVE_OK); @@ -420,14 +416,13 @@ archive_write_ar_free(struct archive_write *a) static int archive_write_ar_close(struct archive_write *a) { - struct ar_w *ar; + struct ar_w *ar = a->format_data; int ret; /* * If we haven't written anything yet, we need to write * the ar global header now to make it a valid ar archive. */ - ar = (struct ar_w *)a->format_data; if (!ar->wrote_global_header) { ar->wrote_global_header = 1; ret = __archive_write_output(a, "!\n", 8); @@ -440,11 +435,9 @@ archive_write_ar_close(struct archive_write *a) static int archive_write_ar_finish_entry(struct archive_write *a) { - struct ar_w *ar; + struct ar_w *ar = a->format_data; int ret; - ar = (struct ar_w *)a->format_data; - if (ar->entry_bytes_remaining != 0) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Entry remaining bytes larger than 0"); diff --git a/libarchive/archive_write_set_format_cpio_binary.c b/libarchive/archive_write_set_format_cpio_binary.c index 7c86072d3..6648b18d9 100644 --- a/libarchive/archive_write_set_format_cpio_binary.c +++ b/libarchive/archive_write_set_format_cpio_binary.c @@ -235,7 +235,7 @@ static int archive_write_binary_options(struct archive_write *a, const char *key, const char *val) { - struct cpio *cpio = (struct cpio *)a->format_data; + struct cpio *cpio = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -335,10 +335,9 @@ synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) static struct archive_string_conv * get_sconv(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; struct archive_string_conv *sconv; - cpio = (struct cpio *)a->format_data; sconv = cpio->opt_sconv; if (sconv == NULL) { if (!cpio->init_default_conversion) { @@ -384,7 +383,7 @@ archive_write_binary_header(struct archive_write *a, struct archive_entry *entry static int write_header(struct archive_write *a, struct archive_entry *entry) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; const char *p, *path; int ret, ret_final; int64_t ino; @@ -393,7 +392,6 @@ write_header(struct archive_write *a, struct archive_entry *entry) struct archive_entry *entry_main; size_t len, pathlength; - cpio = (struct cpio *)a->format_data; ret_final = ARCHIVE_OK; sconv = get_sconv(a); @@ -567,10 +565,9 @@ exit_write_header: static ssize_t archive_write_binary_data(struct archive_write *a, const void *buff, size_t s) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; int ret; - cpio = (struct cpio *)a->format_data; if (s > cpio->entry_bytes_remaining) s = (size_t)cpio->entry_bytes_remaining; @@ -604,9 +601,8 @@ archive_write_binary_close(struct archive_write *a) static int archive_write_binary_free(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; - cpio = (struct cpio *)a->format_data; free(cpio->ino_list); free(cpio); a->format_data = NULL; @@ -616,8 +612,7 @@ archive_write_binary_free(struct archive_write *a) static int archive_write_binary_finish_entry(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; - cpio = (struct cpio *)a->format_data; return (__archive_write_nulls(a, 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 7dfbfa7d5..b9de7d362 100644 --- a/libarchive/archive_write_set_format_cpio_newc.c +++ b/libarchive/archive_write_set_format_cpio_newc.c @@ -137,7 +137,7 @@ static int archive_write_newc_options(struct archive_write *a, const char *key, const char *val) { - struct cpio *cpio = (struct cpio *)a->format_data; + struct cpio *cpio = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -165,10 +165,9 @@ archive_write_newc_options(struct archive_write *a, const char *key, static struct archive_string_conv * get_sconv(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; struct archive_string_conv *sconv; - cpio = (struct cpio *)a->format_data; sconv = cpio->opt_sconv; if (sconv == NULL) { if (!cpio->init_default_conversion) { @@ -215,8 +214,8 @@ archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) static int write_header(struct archive_write *a, struct archive_entry *entry) { + struct cpio *cpio = a->format_data; int64_t ino; - struct cpio *cpio; const char *p, *path; int ret, ret_final; char h[c_header_size]; @@ -225,7 +224,6 @@ write_header(struct archive_write *a, struct archive_entry *entry) size_t len, pathlength; int pad; - cpio = (struct cpio *)a->format_data; ret_final = ARCHIVE_OK; sconv = get_sconv(a); @@ -377,10 +375,9 @@ exit_write_header: static ssize_t archive_write_newc_data(struct archive_write *a, const void *buff, size_t s) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; int ret; - cpio = (struct cpio *)a->format_data; if (s > cpio->entry_bytes_remaining) s = (size_t)cpio->entry_bytes_remaining; @@ -443,9 +440,8 @@ archive_write_newc_close(struct archive_write *a) static int archive_write_newc_free(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; - cpio = (struct cpio *)a->format_data; free(cpio); a->format_data = NULL; return (ARCHIVE_OK); @@ -454,9 +450,8 @@ archive_write_newc_free(struct archive_write *a) static int archive_write_newc_finish_entry(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; - cpio = (struct cpio *)a->format_data; return (__archive_write_nulls(a, cpio->entry_bytes_remaining + cpio->padding)); } diff --git a/libarchive/archive_write_set_format_cpio_odc.c b/libarchive/archive_write_set_format_cpio_odc.c index 3082e060a..c384d4827 100644 --- a/libarchive/archive_write_set_format_cpio_odc.c +++ b/libarchive/archive_write_set_format_cpio_odc.c @@ -132,7 +132,7 @@ static int archive_write_odc_options(struct archive_write *a, const char *key, const char *val) { - struct cpio *cpio = (struct cpio *)a->format_data; + struct cpio *cpio = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -232,10 +232,9 @@ synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) static struct archive_string_conv * get_sconv(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; struct archive_string_conv *sconv; - cpio = (struct cpio *)a->format_data; sconv = cpio->opt_sconv; if (sconv == NULL) { if (!cpio->init_default_conversion) { @@ -281,7 +280,7 @@ archive_write_odc_header(struct archive_write *a, struct archive_entry *entry) static int write_header(struct archive_write *a, struct archive_entry *entry) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; const char *p, *path; int ret, ret_final; int64_t ino; @@ -290,7 +289,6 @@ write_header(struct archive_write *a, struct archive_entry *entry) struct archive_entry *entry_main; size_t len, pathlength; - cpio = (struct cpio *)a->format_data; ret_final = ARCHIVE_OK; sconv = get_sconv(a); @@ -426,10 +424,9 @@ exit_write_header: static ssize_t archive_write_odc_data(struct archive_write *a, const void *buff, size_t s) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; int ret; - cpio = (struct cpio *)a->format_data; if (s > cpio->entry_bytes_remaining) s = (size_t)cpio->entry_bytes_remaining; @@ -493,9 +490,8 @@ archive_write_odc_close(struct archive_write *a) static int archive_write_odc_free(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; - cpio = (struct cpio *)a->format_data; free(cpio->ino_list); free(cpio); a->format_data = NULL; @@ -505,9 +501,8 @@ archive_write_odc_free(struct archive_write *a) static int archive_write_odc_finish_entry(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio = a->format_data; - cpio = (struct cpio *)a->format_data; return (__archive_write_nulls(a, cpio->entry_bytes_remaining)); } diff --git a/libarchive/archive_write_set_format_gnutar.c b/libarchive/archive_write_set_format_gnutar.c index 3dd01e0ca..5a767e1bd 100644 --- a/libarchive/archive_write_set_format_gnutar.c +++ b/libarchive/archive_write_set_format_gnutar.c @@ -202,7 +202,7 @@ static int archive_write_gnutar_options(struct archive_write *a, const char *key, const char *val) { - struct gnutar *gnutar = (struct gnutar *)a->format_data; + struct gnutar *gnutar = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -236,9 +236,8 @@ archive_write_gnutar_close(struct archive_write *a) static int archive_write_gnutar_free(struct archive_write *a) { - struct gnutar *gnutar; + struct gnutar *gnutar = a->format_data; - gnutar = (struct gnutar *)a->format_data; free(gnutar); a->format_data = NULL; return (ARCHIVE_OK); @@ -247,10 +246,9 @@ archive_write_gnutar_free(struct archive_write *a) static int archive_write_gnutar_finish_entry(struct archive_write *a) { - struct gnutar *gnutar; + struct gnutar *gnutar = a->format_data; int ret; - gnutar = (struct gnutar *)a->format_data; ret = __archive_write_nulls(a, gnutar->entry_bytes_remaining + gnutar->entry_padding); gnutar->entry_bytes_remaining = gnutar->entry_padding = 0; @@ -260,10 +258,9 @@ archive_write_gnutar_finish_entry(struct archive_write *a) static ssize_t archive_write_gnutar_data(struct archive_write *a, const void *buff, size_t s) { - struct gnutar *gnutar; + struct gnutar *gnutar = a->format_data; int ret; - gnutar = (struct gnutar *)a->format_data; if (s > gnutar->entry_bytes_remaining) s = (size_t)gnutar->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); @@ -277,15 +274,13 @@ static int archive_write_gnutar_header(struct archive_write *a, struct archive_entry *entry) { + struct gnutar *gnutar = a->format_data; char buff[512]; int r, ret, ret2 = ARCHIVE_OK; char tartype; - struct gnutar *gnutar; struct archive_string_conv *sconv; struct archive_entry *entry_main; - gnutar = (struct gnutar *)a->format_data; - /* Setup default string conversion. */ if (gnutar->opt_sconv == NULL) { if (!gnutar->init_default_conversion) { @@ -608,13 +603,11 @@ static int archive_format_gnutar_header(struct archive_write *a, char h[512], struct archive_entry *entry, char tartype) { + struct gnutar *gnutar = a->format_data; unsigned int checksum; int i, ret; size_t copy_length; const char *p; - struct gnutar *gnutar; - - gnutar = (struct gnutar *)a->format_data; ret = 0; diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c index e00dd32c5..ee50f7c08 100644 --- a/libarchive/archive_write_set_format_iso9660.c +++ b/libarchive/archive_write_set_format_iso9660.c @@ -1528,13 +1528,11 @@ invalid_value: static int iso9660_write_header(struct archive_write *a, struct archive_entry *entry) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; struct isofile *file; struct isoent *isoent; int r, ret = ARCHIVE_OK; - iso9660 = a->format_data; - iso9660->cur_file = NULL; iso9660->bytes_remaining = 0; iso9660->need_multi_extent = 0; @@ -1676,7 +1674,7 @@ wb_write_to_temp(struct archive_write *a, const void *buff, size_t s) * order to reduce a extra memory copy. */ if (wb_remaining(a) == wb_buffmax() && s > (1024 * 16)) { - struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + struct iso9660 *iso9660 = a->format_data; xs = s % LOGICAL_BLOCK_SIZE; iso9660->wbuff_offset += s - xs; if (write_to_temp(a, buff, s - xs) != ARCHIVE_OK) @@ -1858,11 +1856,9 @@ iso9660_finish_entry(struct archive_write *a) static int iso9660_close(struct archive_write *a) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; int ret, blocks; - iso9660 = a->format_data; - /* * Write remaining data out to the temporary file. */ @@ -2120,11 +2116,9 @@ iso9660_close(struct archive_write *a) static int iso9660_free(struct archive_write *a) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; int i, ret; - iso9660 = a->format_data; - /* Close the temporary file. */ if (iso9660->temp_fd >= 0) close(iso9660->temp_fd); @@ -3618,7 +3612,7 @@ get_dir_rec_size(struct iso9660 *iso9660, struct isoent *isoent, static inline unsigned char * wb_buffptr(struct archive_write *a) { - struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + struct iso9660 *iso9660 = a->format_data; return (&(iso9660->wbuff[sizeof(iso9660->wbuff) - iso9660->wbuff_remaining])); @@ -3627,7 +3621,7 @@ wb_buffptr(struct archive_write *a) static int wb_write_out(struct archive_write *a) { - struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + struct iso9660 *iso9660 = a->format_data; size_t wsize, nw; int r; @@ -3652,7 +3646,7 @@ wb_write_out(struct archive_write *a) static int wb_consume(struct archive_write *a, size_t size) { - struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + struct iso9660 *iso9660 = a->format_data; if (size > iso9660->wbuff_remaining || iso9660->wbuff_remaining == 0) { @@ -3673,7 +3667,7 @@ wb_consume(struct archive_write *a, size_t size) static int wb_set_offset(struct archive_write *a, int64_t off) { - struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + struct iso9660 *iso9660 = a->format_data; int64_t used, ext_bytes; if (iso9660->wbuff_type != WB_TO_TEMP) { @@ -3840,7 +3834,7 @@ set_file_identifier(unsigned char *bp, int from, int to, enum vdc vdc, static int write_VD(struct archive_write *a, struct vdd *vdd) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; unsigned char *bp; uint16_t volume_set_size = 1; char identifier[256]; @@ -3849,7 +3843,6 @@ write_VD(struct archive_write *a, struct vdd *vdd) unsigned char vd_ver, fst_ver; int r; - iso9660 = a->format_data; switch (vdd->vdd_type) { case VDD_JOLIET: vdt = VDT_SUPPLEMENTARY; @@ -3987,10 +3980,9 @@ write_VD(struct archive_write *a, struct vdd *vdd) static int write_VD_boot_record(struct archive_write *a) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; unsigned char *bp; - iso9660 = a->format_data; bp = wb_buffptr(a) -1; /* Volume Descriptor Type */ set_VD_bp(bp, VDT_BOOT_RECORD, 1); @@ -4058,7 +4050,7 @@ set_option_info(struct archive_string *info, int *opt, const char *key, static int write_information_block(struct archive_write *a) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; char buf[128]; const char *v; int opt, r; @@ -4066,7 +4058,6 @@ write_information_block(struct archive_write *a) size_t info_size = LOGICAL_BLOCK_SIZE * NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK; - iso9660 = (struct iso9660 *)a->format_data; if (info_size > wb_remaining(a)) { r = wb_write_out(a); if (r != ARCHIVE_OK) @@ -4716,14 +4707,12 @@ cleanup_backslash_2(wchar_t *p) static int isofile_gen_utility_names(struct archive_write *a, struct isofile *file) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; const char *pathname; char *p, *dirname, *slash; size_t len; int ret = ARCHIVE_OK; - iso9660 = a->format_data; - archive_string_empty(&(file->parentdir)); archive_string_empty(&(file->basename)); archive_string_empty(&(file->basename_utf16)); @@ -5562,6 +5551,7 @@ get_path_component(char *name, size_t n, const char *fn) static int isoent_tree(struct archive_write *a, struct isoent **isoentpp) { + struct iso9660 *iso9660 = a->format_data; #if defined(_WIN32) && !defined(__CYGWIN__) char name[_MAX_FNAME];/* Included null terminator size. */ #elif defined(NAME_MAX) && NAME_MAX >= 255 @@ -5569,7 +5559,6 @@ isoent_tree(struct archive_write *a, struct isoent **isoentpp) #else char name[256]; #endif - struct iso9660 *iso9660 = a->format_data; struct isoent *dent, *isoent, *np; struct isofile *f1, *f2; const char *fn, *p; @@ -5997,7 +5986,7 @@ static int isoent_gen_iso9660_identifier(struct archive_write *a, struct isoent *isoent, struct idr *idr) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; struct isoent *np; char *p; int l, r; @@ -6015,7 +6004,6 @@ isoent_gen_iso9660_identifier(struct archive_write *a, struct isoent *isoent, if (isoent->children.cnt == 0) return (ARCHIVE_OK); - iso9660 = a->format_data; char_map = idr->char_map; if (iso9660->opt.iso_level <= 3) { allow_ldots = 0; @@ -6257,7 +6245,7 @@ static int isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent, struct idr *idr) { - struct iso9660 *iso9660; + struct iso9660 *iso9660 = a->format_data; struct isoent *np; unsigned char *p; size_t l; @@ -6272,7 +6260,6 @@ isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent, if (isoent->children.cnt == 0) return (ARCHIVE_OK); - iso9660 = a->format_data; if (iso9660->opt.joliet == OPT_JOLIET_LONGNAME) ffmax = 206; else diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index 9ca4e3177..1d94fbbb6 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -913,7 +913,7 @@ static int archive_write_mtree_header(struct archive_write *a, struct archive_entry *entry) { - struct mtree_writer *mtree= a->format_data; + struct mtree_writer *mtree = a->format_data; struct mtree_entry *mtree_entry; int r, r2; @@ -1261,7 +1261,7 @@ archive_write_mtree_finish_entry(struct archive_write *a) static int archive_write_mtree_close(struct archive_write *a) { - struct mtree_writer *mtree= a->format_data; + struct mtree_writer *mtree = a->format_data; int ret; if (mtree->root != NULL) { @@ -1278,7 +1278,7 @@ archive_write_mtree_close(struct archive_write *a) static ssize_t archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) { - struct mtree_writer *mtree= a->format_data; + struct mtree_writer *mtree = a->format_data; if (n > mtree->entry_bytes_remaining) n = (size_t)mtree->entry_bytes_remaining; @@ -1297,7 +1297,7 @@ archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) static int archive_write_mtree_free(struct archive_write *a) { - struct mtree_writer *mtree= a->format_data; + struct mtree_writer *mtree = a->format_data; if (mtree == NULL) return (ARCHIVE_OK); @@ -1317,7 +1317,7 @@ static int archive_write_mtree_options(struct archive_write *a, const char *key, const char *value) { - struct mtree_writer *mtree= a->format_data; + struct mtree_writer *mtree = a->format_data; int keybit = 0; switch (key[0]) { @@ -1480,9 +1480,7 @@ archive_write_set_format_mtree_classic(struct archive *_a) "archive_write_set_format_mtree_classic"); if (r == ARCHIVE_OK) { struct archive_write *a = (struct archive_write *)_a; - struct mtree_writer *mtree; - - mtree = (struct mtree_writer *)a->format_data; + struct mtree_writer *mtree = a->format_data; /* Set to output a mtree archive in classic format. */ mtree->classic = 1; @@ -2072,6 +2070,7 @@ get_path_component(char *name, size_t n, const char *fn) static int mtree_entry_tree_add(struct archive_write *a, struct mtree_entry **filep) { + struct mtree_writer *mtree = a->format_data; #if defined(_WIN32) && !defined(__CYGWIN__) char name[_MAX_FNAME];/* Included null terminator size. */ #elif defined(NAME_MAX) && NAME_MAX >= 255 @@ -2079,7 +2078,6 @@ mtree_entry_tree_add(struct archive_write *a, struct mtree_entry **filep) #else char name[256]; #endif - struct mtree_writer *mtree = (struct mtree_writer *)a->format_data; struct mtree_entry *dent, *file, *np; const char *fn, *p; int l, r; diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index f76ff5724..1e2726050 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -172,7 +172,7 @@ static int archive_write_pax_options(struct archive_write *a, const char *key, const char *val) { - struct pax *pax = (struct pax *)a->format_data; + struct pax *pax = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -680,6 +680,7 @@ static int archive_write_pax_header(struct archive_write *a, struct archive_entry *entry_original) { + struct pax *pax = a->format_data; struct archive_entry *entry_main; const char *p; const char *suffix; @@ -687,7 +688,6 @@ archive_write_pax_header(struct archive_write *a, int acl_types; int sparse_count; uint64_t sparse_total, real_size; - struct pax *pax; const char *hardlink; const char *path = NULL, *linkpath = NULL; const char *uname = NULL, *gname = NULL; @@ -707,7 +707,6 @@ archive_write_pax_header(struct archive_write *a, ret = ARCHIVE_OK; need_extension = 0; - pax = (struct pax *)a->format_data; const time_t ustar_max_mtime = get_ustar_max_mtime(); @@ -1962,9 +1961,8 @@ archive_write_pax_close(struct archive_write *a) static int archive_write_pax_free(struct archive_write *a) { - struct pax *pax; + struct pax *pax = a->format_data; - pax = (struct pax *)a->format_data; if (pax == NULL) return (ARCHIVE_OK); @@ -1980,11 +1978,10 @@ archive_write_pax_free(struct archive_write *a) static int archive_write_pax_finish_entry(struct archive_write *a) { - struct pax *pax; + struct pax *pax = a->format_data; uint64_t remaining; int ret; - pax = (struct pax *)a->format_data; remaining = pax->entry_bytes_remaining; if (remaining == 0) { while (pax->sparse_list) { @@ -2004,13 +2001,11 @@ archive_write_pax_finish_entry(struct archive_write *a) static ssize_t archive_write_pax_data(struct archive_write *a, const void *buff, size_t s) { - struct pax *pax; + struct pax *pax = a->format_data; size_t ws; size_t total; int ret; - pax = (struct pax *)a->format_data; - /* * According to GNU PAX format 1.0, write a sparse map * before the body. diff --git a/libarchive/archive_write_set_format_raw.c b/libarchive/archive_write_set_format_raw.c index 9b8364026..20c42e3d3 100644 --- a/libarchive/archive_write_set_format_raw.c +++ b/libarchive/archive_write_set_format_raw.c @@ -81,7 +81,7 @@ archive_write_set_format_raw(struct archive *_a) static int archive_write_raw_header(struct archive_write *a, struct archive_entry *entry) { - struct raw *raw = (struct raw *)a->format_data; + struct raw *raw = a->format_data; if (archive_entry_filetype(entry) != AE_IFREG) { archive_set_error(&a->archive, ERANGE, @@ -115,9 +115,8 @@ archive_write_raw_data(struct archive_write *a, const void *buff, size_t s) static int archive_write_raw_free(struct archive_write *a) { - struct raw *raw; + struct raw *raw = a->format_data; - raw = (struct raw *)a->format_data; free(raw); a->format_data = NULL; return (ARCHIVE_OK); diff --git a/libarchive/archive_write_set_format_shar.c b/libarchive/archive_write_set_format_shar.c index 146b4a38d..b6ef91948 100644 --- a/libarchive/archive_write_set_format_shar.c +++ b/libarchive/archive_write_set_format_shar.c @@ -143,11 +143,13 @@ archive_write_set_format_shar_dump(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; struct shar *shar; + int ret; - int ret = archive_write_set_format_shar(&a->archive); + ret = archive_write_set_format_shar(&a->archive); if (ret != ARCHIVE_OK) return ret; - shar = (struct shar *)a->format_data; + + shar = a->format_data; shar->dump = 1; a->format_write_data = archive_write_shar_data_uuencode; a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP; @@ -158,12 +160,11 @@ archive_write_set_format_shar_dump(struct archive *_a) static int archive_write_shar_header(struct archive_write *a, struct archive_entry *entry) { + struct shar *shar = a->format_data; const char *linkname; const char *name; char *p, *pp; - struct shar *shar; - shar = (struct shar *)a->format_data; if (!shar->wrote_header) { archive_strcat(&shar->work, "#!/bin/sh\n"); archive_strcat(&shar->work, "# This is a shell archive\n"); @@ -342,14 +343,13 @@ archive_write_shar_header(struct archive_write *a, struct archive_entry *entry) static ssize_t archive_write_shar_data_sed(struct archive_write *a, const void *buff, size_t n) { + struct shar *shar = a->format_data; static const size_t ensured = 65533; - struct shar *shar; const char *src; char *buf, *buf_end; int ret; size_t written = n; - shar = (struct shar *)a->format_data; if (!shar->has_data || n == 0) return (0); @@ -474,12 +474,11 @@ static ssize_t archive_write_shar_data_uuencode(struct archive_write *a, const void *buff, size_t length) { - struct shar *shar; + struct shar *shar = a->format_data; const char *src; size_t n; int ret; - shar = (struct shar *)a->format_data; if (!shar->has_data) return (ARCHIVE_OK); src = (const char *)buff; @@ -523,11 +522,10 @@ archive_write_shar_data_uuencode(struct archive_write *a, const void *buff, static int archive_write_shar_finish_entry(struct archive_write *a) { + struct shar *shar = a->format_data; const char *g, *p, *u; - struct shar *shar; int ret; - shar = (struct shar *)a->format_data; if (shar->entry == NULL) return (ARCHIVE_OK); @@ -601,7 +599,7 @@ archive_write_shar_finish_entry(struct archive_write *a) static int archive_write_shar_close(struct archive_write *a) { - struct shar *shar; + struct shar *shar = a->format_data; int ret; /* @@ -609,8 +607,6 @@ archive_write_shar_close(struct archive_write *a) * fix them all up at end-of-archive. */ - shar = (struct shar *)a->format_data; - /* * Only write the end-of-archive markers if the archive was * actually started. This avoids problems if someone sets @@ -639,9 +635,8 @@ archive_write_shar_close(struct archive_write *a) static int archive_write_shar_free(struct archive_write *a) { - struct shar *shar; + struct shar *shar = a->format_data; - shar = (struct shar *)a->format_data; if (shar == NULL) return (ARCHIVE_OK); diff --git a/libarchive/archive_write_set_format_ustar.c b/libarchive/archive_write_set_format_ustar.c index d838f34c7..a55cbb75b 100644 --- a/libarchive/archive_write_set_format_ustar.c +++ b/libarchive/archive_write_set_format_ustar.c @@ -205,7 +205,7 @@ static int archive_write_ustar_options(struct archive_write *a, const char *key, const char *val) { - struct ustar *ustar = (struct ustar *)a->format_data; + struct ustar *ustar = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -233,14 +233,12 @@ archive_write_ustar_options(struct archive_write *a, const char *key, static int archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry) { + struct ustar *ustar = a->format_data; char buff[512]; int ret, ret2; - struct ustar *ustar; struct archive_entry *entry_main; struct archive_string_conv *sconv; - ustar = (struct ustar *)a->format_data; - /* Setup default string conversion. */ if (ustar->opt_sconv == NULL) { if (!ustar->init_default_conversion) { @@ -735,9 +733,8 @@ archive_write_ustar_close(struct archive_write *a) static int archive_write_ustar_free(struct archive_write *a) { - struct ustar *ustar; + struct ustar *ustar = a->format_data; - ustar = (struct ustar *)a->format_data; free(ustar); a->format_data = NULL; return (ARCHIVE_OK); @@ -746,10 +743,9 @@ archive_write_ustar_free(struct archive_write *a) static int archive_write_ustar_finish_entry(struct archive_write *a) { - struct ustar *ustar; + struct ustar *ustar = a->format_data; int ret; - ustar = (struct ustar *)a->format_data; ret = __archive_write_nulls(a, ustar->entry_bytes_remaining + ustar->entry_padding); ustar->entry_bytes_remaining = ustar->entry_padding = 0; @@ -759,10 +755,9 @@ archive_write_ustar_finish_entry(struct archive_write *a) static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff, size_t s) { - struct ustar *ustar; + struct ustar *ustar = a->format_data; int ret; - ustar = (struct ustar *)a->format_data; if (s > ustar->entry_bytes_remaining) s = (size_t)ustar->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); diff --git a/libarchive/archive_write_set_format_v7tar.c b/libarchive/archive_write_set_format_v7tar.c index 3f7f3a03e..74875547b 100644 --- a/libarchive/archive_write_set_format_v7tar.c +++ b/libarchive/archive_write_set_format_v7tar.c @@ -182,7 +182,7 @@ static int archive_write_v7tar_options(struct archive_write *a, const char *key, const char *val) { - struct v7tar *v7tar = (struct v7tar *)a->format_data; + struct v7tar *v7tar = a->format_data; int ret = ARCHIVE_FAILED; if (strcmp(key, "hdrcharset") == 0) { @@ -210,14 +210,12 @@ archive_write_v7tar_options(struct archive_write *a, const char *key, static int archive_write_v7tar_header(struct archive_write *a, struct archive_entry *entry) { + struct v7tar *v7tar = a->format_data; char buff[512]; int ret, ret2; - struct v7tar *v7tar; struct archive_entry *entry_main; struct archive_string_conv *sconv; - v7tar = (struct v7tar *)a->format_data; - /* Setup default string conversion. */ if (v7tar->opt_sconv == NULL) { if (!v7tar->init_default_conversion) { @@ -615,9 +613,8 @@ archive_write_v7tar_close(struct archive_write *a) static int archive_write_v7tar_free(struct archive_write *a) { - struct v7tar *v7tar; + struct v7tar *v7tar = a->format_data; - v7tar = (struct v7tar *)a->format_data; free(v7tar); a->format_data = NULL; return (ARCHIVE_OK); @@ -626,10 +623,9 @@ archive_write_v7tar_free(struct archive_write *a) static int archive_write_v7tar_finish_entry(struct archive_write *a) { - struct v7tar *v7tar; + struct v7tar *v7tar = a->format_data; int ret; - v7tar = (struct v7tar *)a->format_data; ret = __archive_write_nulls(a, v7tar->entry_bytes_remaining + v7tar->entry_padding); v7tar->entry_bytes_remaining = v7tar->entry_padding = 0; @@ -639,10 +635,9 @@ archive_write_v7tar_finish_entry(struct archive_write *a) static ssize_t archive_write_v7tar_data(struct archive_write *a, const void *buff, size_t s) { - struct v7tar *v7tar; + struct v7tar *v7tar = a->format_data; int ret; - v7tar = (struct v7tar *)a->format_data; if (s > v7tar->entry_bytes_remaining) s = (size_t)v7tar->entry_bytes_remaining; ret = __archive_write_output(a, buff, s); diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c index da8173e9d..c3e444f7e 100644 --- a/libarchive/archive_write_set_format_xar.c +++ b/libarchive/archive_write_set_format_xar.c @@ -434,9 +434,7 @@ memerr: static int xar_options(struct archive_write *a, const char *key, const char *value) { - struct xar *xar; - - xar = (struct xar *)a->format_data; + struct xar *xar = a->format_data; if (strcmp(key, "checksum") == 0) { if (value == NULL) @@ -566,12 +564,11 @@ xar_options(struct archive_write *a, const char *key, const char *value) static int xar_write_header(struct archive_write *a, struct archive_entry *entry) { - struct xar *xar; + struct xar *xar = a->format_data; struct file *file; struct archive_entry *file_entry; int r, r2; - xar = (struct xar *)a->format_data; xar->cur_file = NULL; xar->bytes_remaining = 0; @@ -696,11 +693,10 @@ xar_write_header(struct archive_write *a, struct archive_entry *entry) static int write_to_temp(struct archive_write *a, const void *buff, size_t s) { - struct xar *xar; + struct xar *xar = a->format_data; const unsigned char *p; ssize_t ws; - xar = (struct xar *)a->format_data; p = (const unsigned char *)buff; while (s) { ws = write(xar->temp_fd, p, s); @@ -719,14 +715,12 @@ write_to_temp(struct archive_write *a, const void *buff, size_t s) static ssize_t xar_write_data(struct archive_write *a, const void *buff, size_t s) { - struct xar *xar; + struct xar *xar = a->format_data; enum la_zaction run; size_t size = 0; size_t rsize; int r; - xar = (struct xar *)a->format_data; - if (s > xar->bytes_remaining) s = (size_t)xar->bytes_remaining; if (s == 0 || xar->cur_file == NULL) @@ -820,12 +814,11 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s) static int xar_finish_entry(struct archive_write *a) { - struct xar *xar; + struct xar *xar = a->format_data; struct file *file; size_t s; ssize_t w; - xar = (struct xar *)a->format_data; if (xar->cur_file == NULL) return (ARCHIVE_OK); @@ -926,10 +919,9 @@ static int __LA_PRINTF(4, 5) xmlwrite_fstring(struct archive_write *a, struct xml_writer *writer, const char *key, const char *fmt, ...) { - struct xar *xar; + struct xar *xar = a->format_data; va_list ap; - xar = (struct xar *)a->format_data; va_start(ap, fmt); archive_string_empty(&xar->vstr); archive_string_vsprintf(&xar->vstr, fmt, ap); @@ -1217,7 +1209,7 @@ static int make_file_entry(struct archive_write *a, struct xml_writer *writer, struct file *file) { - struct xar *xar; + struct xar *xar = a->format_data; const char *filetype, *filelink, *fflags; struct archive_string linkto; struct heap_data *heap; @@ -1225,7 +1217,6 @@ make_file_entry(struct archive_write *a, struct xml_writer *writer, size_t len; int r, r2; - xar = (struct xar *)a->format_data; r2 = ARCHIVE_OK; /* @@ -1587,7 +1578,7 @@ make_file_entry(struct archive_write *a, struct xml_writer *writer, static int make_toc(struct archive_write *a) { - struct xar *xar; + struct xar *xar = a->format_data; struct file *np; struct xml_writer *writer; const char* content; @@ -1595,8 +1586,6 @@ make_toc(struct archive_write *a) int algsize; int r, ret; - xar = (struct xar *)a->format_data; - ret = ARCHIVE_FATAL; /* @@ -1837,11 +1826,10 @@ exit_toc: static int flush_wbuff(struct archive_write *a) { - struct xar *xar; + struct xar *xar = a->format_data; int r; size_t s; - xar = (struct xar *)a->format_data; s = sizeof(xar->wbuff) - xar->wbuff_remaining; r = __archive_write_output(a, xar->wbuff, s); if (r != ARCHIVE_OK) @@ -1853,10 +1841,9 @@ flush_wbuff(struct archive_write *a) static int copy_out(struct archive_write *a, uint64_t offset, uint64_t length) { - struct xar *xar; + struct xar *xar = a->format_data; int r; - xar = (struct xar *)a->format_data; if (lseek(xar->temp_fd, offset, SEEK_SET) < 0) { archive_set_error(&(a->archive), errno, "lseek failed"); return (ARCHIVE_FATAL); @@ -1898,13 +1885,11 @@ copy_out(struct archive_write *a, uint64_t offset, uint64_t length) static int xar_close(struct archive_write *a) { - struct xar *xar; + struct xar *xar = a->format_data; unsigned char *wb; uint64_t length; int r; - xar = (struct xar *)a->format_data; - /* Empty! */ if (xar->root->children.first == NULL) return (ARCHIVE_OK); @@ -1964,9 +1949,7 @@ xar_close(struct archive_write *a) static int xar_free(struct archive_write *a) { - struct xar *xar; - - xar = (struct xar *)a->format_data; + struct xar *xar = a->format_data; /* Close the temporary file. */ if (xar->temp_fd >= 0) @@ -2124,13 +2107,12 @@ cleanup_backslash(char *utf8, size_t len) static int file_gen_utility_names(struct archive_write *a, struct file *file) { - struct xar *xar; + struct xar *xar = a->format_data; const char *pp; char *p, *dirname, *slash; size_t len; int r = ARCHIVE_OK; - xar = (struct xar *)a->format_data; archive_string_empty(&(file->parentdir)); archive_string_empty(&(file->basename)); archive_string_empty(&(file->symlink)); @@ -2318,6 +2300,7 @@ get_path_component(char *name, int n, const char *fn) static int file_tree(struct archive_write *a, struct file **filepp) { + struct xar *xar = a->format_data; #if defined(_WIN32) && !defined(__CYGWIN__) char name[_MAX_FNAME];/* Included null terminator size. */ #elif defined(NAME_MAX) && NAME_MAX >= 255 @@ -2325,7 +2308,6 @@ file_tree(struct archive_write *a, struct file **filepp) #else char name[256]; #endif - struct xar *xar = (struct xar *)a->format_data; struct file *dent, *file, *np; struct archive_entry *ent; const char *fn, *p; @@ -2545,7 +2527,7 @@ file_free_register(struct xar *xar) static int file_register_hardlink(struct archive_write *a, struct file *file) { - struct xar *xar = (struct xar *)a->format_data; + struct xar *xar = a->format_data; struct hardlink *hl; const char *pathname; @@ -3151,10 +3133,9 @@ compression_init_encoder_xz(struct archive *a, static int xar_compression_init_encoder(struct archive_write *a) { - struct xar *xar; + struct xar *xar = a->format_data; int r; - xar = (struct xar *)a->format_data; switch (xar->opt_compression) { case GZIP: r = compression_init_encoder_gzip( @@ -3211,14 +3192,13 @@ compression_end(struct archive *a, struct la_zstream *lastrm) static int save_xattrs(struct archive_write *a, struct file *file) { - struct xar *xar; + struct xar *xar = a->format_data; const char *name; const void *value; struct heap_data *heap; size_t size; int count, r; - xar = (struct xar *)a->format_data; count = archive_entry_xattr_reset(file->entry); if (count == 0) return (ARCHIVE_OK); diff --git a/libarchive/archive_write_set_format_zip.c b/libarchive/archive_write_set_format_zip.c index 94b66d0d7..9c7073fb7 100644 --- a/libarchive/archive_write_set_format_zip.c +++ b/libarchive/archive_write_set_format_zip.c @@ -789,9 +789,9 @@ is_all_ascii(const char *p) static int archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) { + struct zip *zip = a->format_data; unsigned char local_header[32]; unsigned char local_extra[144]; - struct zip *zip = a->format_data; unsigned char *e; unsigned char *cd_extra; size_t filename_length; @@ -1520,8 +1520,8 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) static ssize_t archive_write_zip_data(struct archive_write *a, const void *buff, size_t s) { - int ret; struct zip *zip = a->format_data; + int ret; if ((int64_t)s > zip->entry_uncompressed_limit) s = (size_t)zip->entry_uncompressed_limit; @@ -2189,9 +2189,9 @@ archive_write_zip_finish_entry(struct archive_write *a) static int archive_write_zip_close(struct archive_write *a) { + struct zip *zip = a->format_data; uint8_t buff[64]; int64_t offset_start, offset_end; - struct zip *zip = a->format_data; struct cd_segment *segment; int ret; @@ -2261,10 +2261,9 @@ archive_write_zip_close(struct archive_write *a) static int archive_write_zip_free(struct archive_write *a) { - struct zip *zip; + struct zip *zip = a->format_data; struct cd_segment *segment; - zip = a->format_data; while (zip->central_directory != NULL) { segment = zip->central_directory; zip->central_directory = segment->next;