Fix some compiler warnings
authorEric Biggers <ebiggers3@gmail.com>
Mon, 13 Aug 2012 02:38:52 +0000 (21:38 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Mon, 13 Aug 2012 02:38:52 +0000 (21:38 -0500)
14 files changed:
programs/imagex.c
src/dentry.c
src/header.c
src/lookup_table.c
src/lookup_table.h
src/lzx-comp.c
src/modify.c
src/mount.c
src/resource.c
src/security.c
src/split.c
src/util.c
src/wim.c
src/write.c

index fb9201cb330889776eb1cc75030e5dd98dff1837..2d664084606ae10c8e2d09eb99e2e76ea820bafa 100644 (file)
@@ -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;
                }
index 9cd9af02927a64901a2486cc080b7e54e0563a4f..4dd26ee0352ab8f71194ed2c46975fdf6e10aa2b 100644 (file)
@@ -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
index b39f9fcc5d2ec47e823a348d583736394a174d40..6d00ccb46a7aaf319e876365c20be1d68174f36d 100644 (file)
@@ -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");
        
index 828c183048a7d55aec46f5a9844a37cbac3784eb..1f6384cfcf6d9f9d945d88b2d6406b7d394a068a 100644 (file)
@@ -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];
 
index 5620e678e865c2f3859e35bf60821273eb543f05..91684c4319ab3fcaaacfc945e9cca2916ac44516 100644 (file)
@@ -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
index 9115ddf90b44a501437c86a1c4a43c63cc428094..0f120791c67fd231073e3a85a6a3672a02efe3a2 100644 (file)
@@ -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;
                }
 
index 2ad0357602134deea224fc7579aebaf7421d1fdc..ce362d6904f7c424a6d7fc065f9b01ee71fd1009 100644 (file)
@@ -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, 
index 10e5d7de1b2c8deb420343b4342fa1224cc9341f..3cb61ee6d319376ec57cc04569d2f224f79749f3 100644 (file)
@@ -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;
index 2f984d13be8ca2487f9e5c5fd031bac88ba88faa..a5f0e4d70ba9050b8e3f3380936d0929e6431c25 100644 (file)
@@ -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;
index 089067dc433f5152cd6cd4fd15261744d56eb48d..65d8555c989a1373976d0316413cf2e24131ffbd 100644 (file)
@@ -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);
index 0321492e7d7cfddc49aec925ba695859039dfaa3..25cca9f92310d13923b58fc34cc7d62604c6f858 100644 (file)
@@ -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)
index 690fd4d2496095879463dbb8cbad81b239437f3a..bdd0a294dc7655ab28a571e2e92f47928d9bd6fd 100644 (file)
@@ -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 "
index 2f008f8f44cd6f849c03d642debdd5cabd5e996f..b166ba8ceea4dc01492b420c721469b538b0c2fa 100644 (file)
--- 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;
 
index 3bd2f7804137d8b63a0c33062aeb893967de90ac..c46494ed19094414cfe59d5a8b5ba7dc81197099 100644 (file)
@@ -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;