From 53d4db68e30bf45b983c59f91e5e2a3e039e1426 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 12 Aug 2012 21:38:52 -0500 Subject: [PATCH] Fix some compiler warnings --- programs/imagex.c | 12 ++++++------ src/dentry.c | 2 +- src/header.c | 2 -- src/lookup_table.c | 4 ++-- src/lookup_table.h | 13 +++++++++++-- src/lzx-comp.c | 4 ++-- src/modify.c | 28 +++++++++++----------------- src/mount.c | 7 +++---- src/resource.c | 2 +- src/security.c | 4 ++-- src/split.c | 7 +++---- src/util.c | 1 + src/wim.c | 2 +- src/write.c | 1 - 14 files changed, 44 insertions(+), 45 deletions(-) diff --git a/programs/imagex.c b/programs/imagex.c index fb9201cb..2d664084 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -1011,8 +1011,6 @@ static int imagex_join(int argc, const char **argv) { int c; int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS; - int image; - int ret; const char *output_path; for_opt(c, join_options) { @@ -1042,7 +1040,6 @@ err: /* Mounts an image using a FUSE mount. */ static int imagex_mount_rw_or_ro(int argc, const char **argv) { - bool ro; int c; int mount_flags = 0; int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS; @@ -1064,14 +1061,16 @@ static int imagex_mount_rw_or_ro(int argc, const char **argv) mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG; break; default: - usage(ro ? MOUNT : MOUNTRW); + usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) + ? MOUNTRW : MOUNT); return -1; } } argc -= optind; argv += optind; if (argc != 2 && argc != 3) { - usage(ro ? MOUNT : MOUNTRW); + usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) + ? MOUNTRW : MOUNT); return -1; } @@ -1087,7 +1086,8 @@ static int imagex_mount_rw_or_ro(int argc, const char **argv) if (num_images != 1) { imagex_error("The file `%s' contains %d images; Please " "select one.\n", wimfile, num_images); - usage(ro ? MOUNT : MOUNTRW); + usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) + ? MOUNTRW : MOUNT); ret = WIMLIB_ERR_INVALID_IMAGE; goto done; } diff --git a/src/dentry.c b/src/dentry.c index 9cd9af02..4dd26ee0 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -642,7 +642,7 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, p = get_u32(p, &dentry->attributes); #ifdef ENABLE_SECURITY_DATA - p = get_u32(p, &dentry->security_id); + p = get_u32(p, (u32*)&dentry->security_id); #else p += sizeof(u32); #endif diff --git a/src/header.c b/src/header.c index b39f9fcc..6d00ccb4 100644 --- a/src/header.c +++ b/src/header.c @@ -42,8 +42,6 @@ int read_header(FILE *fp, struct wim_header *hdr, int split_ok) u32 hdr_size; u32 wim_version; u32 chunk_size; - u16 part_number; - u16 total_parts; DEBUG("Reading WIM header.\n"); diff --git a/src/lookup_table.c b/src/lookup_table.c index 828c1830..1f6384cf 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -84,7 +84,7 @@ void lookup_table_insert(struct lookup_table *table, struct lookup_table_entry *lte) { size_t pos; - pos = *(size_t*)lte->hash % table->capacity; + pos = lte->hash_short % table->capacity; lte->next = table->array[pos]; table->array[pos] = lte; /* XXX Make the table grow when too many entries have been inserted. */ @@ -99,7 +99,7 @@ void lookup_table_unlink(struct lookup_table *table, size_t pos; struct lookup_table_entry *prev, *cur_entry, *next; - pos = *(size_t*)lte->hash % table->capacity; + pos = lte->hash_short % table->capacity; prev = NULL; cur_entry = table->array[pos]; diff --git a/src/lookup_table.h b/src/lookup_table.h index 5620e678..91684c43 100644 --- a/src/lookup_table.h +++ b/src/lookup_table.h @@ -35,8 +35,17 @@ struct lookup_table_entry { /* Number of times this lookup table entry is referenced by dentries. */ u32 refcnt; - /* SHA1 hash of the file resource pointed to by this lookup table entry */ - u8 hash[WIM_HASH_SIZE]; + union { + /* SHA1 hash of the file resource pointed to by this lookup + * table entry */ + u8 hash[WIM_HASH_SIZE]; + + /* First 4 or 8 bytes of the SHA1 hash, used for inserting the + * entry into the hash table. Since the SHA1 hashes can be + * considered random, we don't really need the full 20 byte hash + * just to insert the entry in a hash table. */ + size_t hash_short; + }; /* If @file_on_disk != NULL, the file resource indicated by this lookup * table entry is not in the WIM file, but rather a file on disk; this diff --git a/src/lzx-comp.c b/src/lzx-comp.c index 9115ddf9..0f120791 100644 --- a/src/lzx-comp.c +++ b/src/lzx-comp.c @@ -470,7 +470,7 @@ static int lzx_write_compressed_tree(struct output_bitstream *out, if (delta < 0) delta += 17; pretree_freqs[19]++; - pretree_freqs[delta]++; + pretree_freqs[(unsigned char)delta]++; output_syms[output_syms_idx++] = 19; output_syms[output_syms_idx++] = additional_bits; output_syms[output_syms_idx++] = delta; @@ -486,7 +486,7 @@ static int lzx_write_compressed_tree(struct output_bitstream *out, if (delta < 0) delta += 17; - pretree_freqs[delta]++; + pretree_freqs[(unsigned char)delta]++; output_syms[output_syms_idx++] = delta; } diff --git a/src/modify.c b/src/modify.c index 2ad03576..ce362d69 100644 --- a/src/modify.c +++ b/src/modify.c @@ -261,7 +261,6 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim, const char *dest_description, int flags) { - int boot_idx; int i; int ret; struct dentry *root; @@ -272,34 +271,29 @@ WIMLIBAPI int wimlib_export_image(WIMStruct *src_wim, /* multi-image export. */ - if (flags & WIMLIB_EXPORT_FLAG_BOOT) { - + if ((flags & WIMLIB_EXPORT_FLAG_BOOT) && + (src_wim->hdr.boot_idx == 0)) + { /* Specifying the boot flag on a multi-image * source WIM makes the boot index default to * the bootable image in the source WIM. It is * an error if there is no such bootable image. * */ - - if (src_wim->hdr.boot_idx == 0) { - ERROR("Cannot specify `boot' flag " - "when exporting multiple " - "images from a WIM with no " - "bootable images!\n"); - return WIMLIB_ERR_INVALID_PARAM; - } else { - boot_idx = src_wim->hdr.boot_idx; - } + ERROR("Cannot specify `boot' flag when " + "exporting multiple images from a WIM " + "with no bootable images!\n"); + return WIMLIB_ERR_INVALID_PARAM; } if (dest_name || dest_description) { - ERROR("Image name or image description " - "was specified, but we are exporting " - "multiple images!\n"); + ERROR("Image name or image description was " + "specified, but we are exporting " + "multiple images!\n"); return WIMLIB_ERR_INVALID_PARAM; } for (i = 1; i <= src_wim->hdr.image_count; i++) { int export_flags = flags; - if (i != boot_idx) + if (i != src_wim->hdr.boot_idx) export_flags &= ~WIMLIB_EXPORT_FLAG_BOOT; ret = wimlib_export_image(src_wim, i, dest_wim, diff --git a/src/mount.c b/src/mount.c index 10e5d7de..3cb61ee6 100644 --- a/src/mount.c +++ b/src/mount.c @@ -631,7 +631,6 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi) /* no lookup table entry, so the file must be empty. Create a * lookup table entry for the file. */ char *tmpfile_name; - int err; int fd; lte = new_lookup_table_entry(); @@ -641,9 +640,9 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi) fd = create_staging_file(&tmpfile_name); if (fd == -1) { - err = errno; + int err = errno; free(lte); - return -errno; + return -err; } lte->resource_entry.original_size = 0; randomize_byte_array(lte->hash, WIM_HASH_SIZE); @@ -873,7 +872,7 @@ static int extract_resource_to_staging_dir(struct dentry *dentry, struct lookup_table_entry *lte, u64 size) { - int err, fd; + int fd; bool ret; char *staging_file_name; struct lookup_table_entry *new_lte; diff --git a/src/resource.c b/src/resource.c index 2f984d13..a5f0e4d7 100644 --- a/src/resource.c +++ b/src/resource.c @@ -1018,7 +1018,7 @@ int write_metadata_resource(WIMStruct *w) u8 *buf; u8 *p; int ret; - off_t subdir_offset; + u64 subdir_offset; struct dentry *root; struct lookup_table_entry *lte; struct resource_entry *res_entry; diff --git a/src/security.c b/src/security.c index 089067dc..65d8555c 100644 --- a/src/security.c +++ b/src/security.c @@ -74,7 +74,7 @@ int read_security_data(const u8 metadata_resource[], u64 size_no_descriptors = 8 + sizes_size; if (size_no_descriptors > sd->total_length) { - ERROR("Security data total length of %"PRIu64" is too short because\n" + ERROR("Security data total length of %u is too short because\n" "there must be at least %"PRIu64" bytes of security " "data!\n", sd->total_length, 8 + sizes_size); @@ -110,7 +110,7 @@ int read_security_data(const u8 metadata_resource[], for (uint i = 0; i < sd->num_entries; i++) { total_len += sd->sizes[i]; if (total_len > sd->total_length) { - ERROR("Security data total length of %"PRIu64" is too " + ERROR("Security data total length of %u is too " "short because there are at least %"PRIu64" " "bytes of security data!\n", sd->total_length, total_len); diff --git a/src/split.c b/src/split.c index 0321492e..25cca9f9 100644 --- a/src/split.c +++ b/src/split.c @@ -82,7 +82,6 @@ static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) { struct args *args = (struct args*)__args; WIMStruct *w = args->w; - FILE *out_fp = w->out_fp; int ret; /* metadata resources were already written. */ @@ -244,9 +243,9 @@ WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, ERROR("Failed to open `%s': %m\n", p); return WIMLIB_ERR_OPEN; } - char buf[4]; - put_u16(buf, i); - put_u16(buf + 2, total_parts); + u8 buf[4]; + put_u16(&buf[0], i); + put_u16(&buf[2], total_parts); if (fseek(fp, 40, SEEK_SET) != 0 || fwrite(buf, 1, sizeof(buf), fp) != sizeof(buf) diff --git a/src/util.c b/src/util.c index 690fd4d2..bdd0a294 100644 --- a/src/util.c +++ b/src/util.c @@ -219,6 +219,7 @@ WIMLIBAPI int wimlib_set_memory_allocator(void *(*malloc_func)(size_t), xml_set_memory_allocator(wimlib_malloc_func, wimlib_free_func, wimlib_realloc_func); + return 0; #else ERROR("Cannot set custom memory allocator functions:\n"); ERROR("wimlib was compiled with the " diff --git a/src/wim.c b/src/wim.c index 2f008f8f..b166ba8c 100644 --- a/src/wim.c +++ b/src/wim.c @@ -66,7 +66,7 @@ WIMStruct *new_wim_struct() */ int for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *)) { - int ret; + int ret = 0; int i; int image_count; diff --git a/src/write.c b/src/write.c index 3bd2f780..c46494ed 100644 --- a/src/write.c +++ b/src/write.c @@ -265,7 +265,6 @@ int finish_write(WIMStruct *w, int image, int flags, int write_lt) off_t end_offset; off_t integrity_size; int ret; - int i; struct wim_header hdr; FILE *out = w->out_fp; -- 2.43.0