From: Eric Biggers Date: Sun, 28 Oct 2012 19:46:25 +0000 (-0500) Subject: Fixes to get rid of various compiler warnings X-Git-Tag: v1.0.4~17 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=7231431086332de22b2556477bcc5fc2c3e4bdcf Fixes to get rid of various compiler warnings --- diff --git a/programs/imagex.c b/programs/imagex.c index 688b1e17..e27f2647 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -199,24 +199,6 @@ static void imagex_error_with_errno(const char *format, ...) va_end(va); } -static const char *path_basename(const char *path) -{ - const char *p = path; - while (*p) - p++; - p--; - - /* Trailing slashes. */ - while ((p != path - 1) && *p == '/') - p--; - - while ((p != path - 1) && *p != '/') - p--; - - return p + 1; -} - - static int verify_image_exists(int image) { if (image == WIM_NO_IMAGE) { diff --git a/src/dentry.c b/src/dentry.c index 39505b75..ee33d124 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -740,9 +740,7 @@ static void put_inode(struct inode *inode) */ void free_dentry(struct dentry *dentry) { - wimlib_assert(dentry); - struct inode *inode; - + wimlib_assert(dentry != NULL); FREE(dentry->file_name); FREE(dentry->file_name_utf8); FREE(dentry->short_name); @@ -754,8 +752,8 @@ void free_dentry(struct dentry *dentry) void put_dentry(struct dentry *dentry) { - wimlib_assert(dentry); - wimlib_assert(dentry->refcnt); + wimlib_assert(dentry != NULL); + wimlib_assert(dentry->refcnt != 0); if (--dentry->refcnt == 0) free_dentry(dentry); @@ -901,7 +899,7 @@ static int verify_inode(struct inode *inode, const WIMStruct *w) WARNING("The following lookup table entry " "has a reference count of %u, but", lte->refcnt); - WARNING("We found %zu references to it", + WARNING("We found %u references to it", lte->real_refcnt); WARNING("(One dentry referencing it is at `%s')", first_dentry->full_path_utf8); @@ -951,12 +949,10 @@ out: /* Run some miscellaneous verifications on a WIM dentry */ int verify_dentry(struct dentry *dentry, void *wim) { - const WIMStruct *w = wim; - const struct inode *inode = dentry->d_inode; int ret; if (!dentry->d_inode->verified) { - ret = verify_inode(dentry->d_inode, w); + ret = verify_inode(dentry->d_inode, wim); if (ret != 0) return ret; } @@ -1378,7 +1374,8 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, "short_name_len = %hu, file_name_len = %hu)", calculated_size, dentry->length, short_name_len, file_name_len); - return WIMLIB_ERR_INVALID_DENTRY; + ret = WIMLIB_ERR_INVALID_DENTRY; + goto out_free_inode; } /* Read the filename if present. Note: if the filename is empty, there @@ -1388,7 +1385,8 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, if (!file_name) { ERROR("Failed to allocate %hu bytes for dentry file name", file_name_len); - return WIMLIB_ERR_NOMEM; + ret = WIMLIB_ERR_NOMEM; + goto out_free_inode; } p = get_bytes(p, file_name_len, file_name); @@ -1480,7 +1478,7 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, calculated_size, dentry->length); } u64 lengths_to_try[3] = {calculated_size, - dentry->length + 7 & ~7, + (dentry->length + 7) & ~7, dentry->length}; ret = WIMLIB_ERR_INVALID_DENTRY; for (size_t i = 0; i < ARRAY_LEN(lengths_to_try); i++) { diff --git a/src/endianness.h b/src/endianness.h index 72a37358..584b6217 100644 --- a/src/endianness.h +++ b/src/endianness.h @@ -59,28 +59,29 @@ static inline uint64_t bswap64(uint64_t n) # endif #endif -static inline void array_cpu_to_le32(uint32_t *p, uint64_t n) +static inline void array_cpu_to_le32(uint32_t *p, size_t n) { - while (n--) - *p++ = cpu_to_le32(*p); + for (size_t i = 0; i < n; i++) + p[i] = cpu_to_le32(p[i]); } -static inline void array_le32_to_cpu(uint32_t *p, uint64_t n) +static inline void array_le32_to_cpu(uint32_t *p, size_t n) { - while (n--) - *p++ = le32_to_cpu(*p); + for (size_t i = 0; i < n; i++) + p[i] = le32_to_cpu(p[i]); } -static inline void array_cpu_to_le64(uint64_t *p, uint64_t n) +static inline void array_cpu_to_le64(uint64_t *p, size_t n) { - while (n--) - *p++ = cpu_to_le64(*p); + for (size_t i = 0; i < n; i++) + p[i] = cpu_to_le64(p[i]); } -static inline void array_le64_to_cpu(uint64_t *p, uint64_t n) +static inline void array_le64_to_cpu(uint64_t *p, size_t n) { - while (n--) - *p++ = le64_to_cpu(*p); + for (size_t i = 0; i < n; i++) + p[i] = le64_to_cpu(p[i]); } + #endif /* _WIMLIB_ENDIANNESS_H */ diff --git a/src/hardlink.c b/src/hardlink.c index b88f4555..2fd38570 100644 --- a/src/hardlink.c +++ b/src/hardlink.c @@ -280,7 +280,7 @@ static int fix_true_inode(struct inode *inode, struct hlist_head *inode_list) static int fix_nominal_inode(struct inode *inode, struct hlist_head *inode_list) { - struct dentry *dentry, *ref_dentry; + struct dentry *dentry; struct hlist_node *cur, *tmp; int ret; size_t num_true_inodes; @@ -315,7 +315,7 @@ fix_nominal_inode(struct inode *inode, struct hlist_head *inode_list) if (list_empty(&dentries_with_data_streams)) { #ifdef ENABLE_DEBUG if (inode->link_count > 1) { - DEBUG("Found link group of size %zu without " + DEBUG("Found link group of size %u without " "any data streams:", inode->link_count); print_inode_dentries(inode); DEBUG("We are going to interpret it as true " diff --git a/src/join.c b/src/join.c index a6e8c9cb..aae6a313 100644 --- a/src/join.c +++ b/src/join.c @@ -280,22 +280,17 @@ static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim, WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms, const char *output_path, int flags) { - int i; int ret; - int part_idx; int write_flags = 0; WIMStruct *joined_wim = NULL; WIMStruct *swms[num_swms]; - int ctype; - u8 *guid; - if (num_swms < 1) return WIMLIB_ERR_INVALID_PARAM; ZERO_ARRAY(swms); - for (i = 0; i < num_swms; i++) { + for (unsigned i = 0; i < num_swms; i++) { ret = wimlib_open_wim(swm_names[i], flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &swms[i]); if (ret != 0) @@ -331,7 +326,7 @@ WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms, out: /* out_fp is the same in all the swms and joined_wim. And it was * already closed in the call to finish_write(). */ - for (i = 0; i < num_swms; i++) { + for (unsigned i = 0; i < num_swms; i++) { swms[i]->out_fp = NULL; wimlib_free(swms[i]); } diff --git a/src/lookup_table.c b/src/lookup_table.c index cc71c8be..e22bd4ed 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -122,6 +122,8 @@ clone_lookup_table_entry(const struct lookup_table_entry *old) } break; #endif + default: + break; } return new; out_free: diff --git a/src/modify.c b/src/modify.c index 76049d8d..9b564bd8 100644 --- a/src/modify.c +++ b/src/modify.c @@ -389,7 +389,7 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry, if (!imd) { ERROR("Failed to allocate memory for new image metadata array"); - return WIMLIB_ERR_NOMEM; + goto err; } memcpy(imd, w->image_metadata, @@ -397,7 +397,7 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry, metadata_lte = new_lookup_table_entry(); if (!metadata_lte) - goto out_free_imd; + goto err_free_imd; metadata_lte->resource_entry.flags = WIM_RESHDR_FLAG_METADATA; random_hash(metadata_lte->hash); @@ -420,10 +420,9 @@ static int add_new_dentry_tree(WIMStruct *w, struct dentry *root_dentry, ret = select_wim_image(w, w->hdr.image_count); wimlib_assert(ret == 0); return ret; -out_free_metadata_lte: - FREE(metadata_lte); -out_free_imd: +err_free_imd: FREE(imd); +err: return WIMLIB_ERR_NOMEM; } diff --git a/src/mount.c b/src/mount.c index 6bff87d4..4fe3dddd 100644 --- a/src/mount.c +++ b/src/mount.c @@ -391,7 +391,7 @@ static int extract_resource_to_staging_dir(struct inode *inode, * */ wimlib_assert(old_lte->refcnt > inode->link_count); DEBUG("Splitting lookup table entry " - "(inode->link_count = %zu, old_lte->refcnt = %u)", + "(inode->link_count = %u, old_lte->refcnt = %u)", inode->link_count, old_lte->refcnt); } @@ -430,7 +430,7 @@ static int extract_resource_to_staging_dir(struct inode *inode, j++; } } - DEBUG("%zu fd's were already opened to the file we extracted", + DEBUG("%hu fd's were already opened to the file we extracted", new_lte->num_opened_fds); if (old_lte) { old_lte->num_opened_fds -= new_lte->num_opened_fds; @@ -468,7 +468,6 @@ out_revert_fd_changes: j++; } } -out_free_new_lte: free_lookup_table_entry(new_lte); out_delete_staging_file: unlink(staging_file_name); @@ -911,12 +910,13 @@ static void wimfs_destroy(void *p) status = 0; if (ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) { if (commit) { - if (chdir(ctx->working_directory)) { + ret = chdir(ctx->working_directory); + if (ret == 0) { + status = rebuild_wim(ctx, (check_integrity != 0)); + } else { ERROR_WITH_ERRNO("chdir()"); status = WIMLIB_ERR_NOTDIR; - goto out; } - status = rebuild_wim(ctx, (check_integrity != 0)); } ret = delete_staging_dir(ctx); if (ret != 0) { @@ -927,12 +927,10 @@ static void wimfs_destroy(void *p) } else { DEBUG("Read-only mount"); } -out: DEBUG("Sending status %hhd", status); ret = mq_send(ctx->daemon_to_unmount_mq, &status, 1, 1); if (ret == -1) ERROR_WITH_ERRNO("Failed to send status to unmount process"); -out_free_mailbox: FREE(mailbox); out_close_message_queues: close_message_queues(ctx); @@ -1077,9 +1075,7 @@ static int wimfs_link(const char *to, const char *from) #ifdef ENABLE_XATTR static int wimfs_listxattr(const char *path, char *list, size_t size) { - int ret; size_t needed_size; - unsigned i; struct inode *inode; struct wimfs_context *ctx = wimfs_get_context(); @@ -1094,12 +1090,12 @@ static int wimfs_listxattr(const char *path, char *list, size_t size) if (size == 0) { needed_size = 0; - for (i = 0; i < inode->num_ads; i++) + for (u16 i = 0; i < inode->num_ads; i++) needed_size += inode->ads_entries[i].stream_name_utf8_len + 6; return needed_size; } else { char *p = list; - for (i = 0; i < inode->num_ads; i++) { + for (u16 i = 0; i < inode->num_ads; i++) { needed_size = inode->ads_entries[i].stream_name_utf8_len + 6; if (needed_size > size) return -ERANGE; @@ -1646,10 +1642,8 @@ static int wimfs_unlink(const char *path) { struct dentry *dentry; struct lookup_table_entry *lte; - struct inode *inode; int ret; u16 stream_idx; - unsigned i; struct wimfs_context *ctx = wimfs_get_context(); ret = lookup_resource(ctx->w, path, get_lookup_flags(ctx), diff --git a/src/ntfs-apply.c b/src/ntfs-apply.c index 56b3e701..db629d94 100644 --- a/src/ntfs-apply.c +++ b/src/ntfs-apply.c @@ -263,7 +263,7 @@ apply_file_attributes_and_security_data(ntfs_inode *ni, sd = wim_const_security_data(w); wimlib_assert(dentry->d_inode->security_id < sd->num_entries); - descriptor = sd->descriptors[dentry->d_inode->security_id]; + descriptor = (const char *)sd->descriptors[dentry->d_inode->security_id]; DEBUG("Applying security descriptor %d to `%s'", dentry->d_inode->security_id, dentry->full_path_utf8); @@ -413,8 +413,6 @@ static int do_wim_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni, if (inode->attributes & FILE_ATTRIBUTE_DIRECTORY) { type = S_IFDIR; } else { - struct dentry *other; - /* Apply hard-linked directory in same directory with DOS name * (if there is one) before this dentry */ if (dentry->short_name_len == 0) { diff --git a/src/ntfs-capture.c b/src/ntfs-capture.c index 47df4085..a4f0b6ed 100644 --- a/src/ntfs-capture.c +++ b/src/ntfs-capture.c @@ -271,7 +271,6 @@ static int capture_ntfs_streams(struct dentry *dentry, ntfs_inode *ni, CASE_SENSITIVE, 0, NULL, 0, actx)) { char *stream_name_utf8; - size_t stream_name_utf16_len; u32 reparse_tag; u64 data_size = ntfs_get_attribute_value_length(actx->attr); u64 name_length = actx->attr->name_length; @@ -508,7 +507,6 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p, { u32 attributes; int mrec_flags; - u32 sd_size = 0; int ret; char dos_name_utf8[64]; struct dentry *root; diff --git a/src/resource.c b/src/resource.c index 4832030c..c6da07a2 100644 --- a/src/resource.c +++ b/src/resource.c @@ -504,11 +504,8 @@ int read_wim_resource(const struct lookup_table_entry *lte, u8 buf[], wimlib_assert(lte->ntfs_loc != NULL); wimlib_assert(lte->attr != NULL); { - u64 adjusted_offset; if (lte->ntfs_loc->is_reparse_point) - adjusted_offset = offset + 8; - else - adjusted_offset = offset; + offset += 8; if (ntfs_attr_pread(lte->attr, offset, size, buf) != size) { ERROR_WITH_ERRNO("Error reading NTFS attribute " "at `%s'", @@ -1203,7 +1200,7 @@ int read_metadata_resource(WIMStruct *w, struct image_metadata *imd) if (ret != 0) goto out_free_buf; - dentry_offset = imd->security_data->total_length + 7 & ~7; + dentry_offset = (imd->security_data->total_length + 7) & ~7; if (dentry_offset == 0) { ERROR("Integer overflow while reading metadata resource"); diff --git a/src/security.c b/src/security.c index ec1590f6..c9550500 100644 --- a/src/security.c +++ b/src/security.c @@ -40,7 +40,7 @@ * entries anyway; however this ensures that that the security descriptors pass * the validation in libntfs-3g. */ -static void empty_sacl_fixup(char *descr, u64 *size_p) +static void empty_sacl_fixup(u8 *descr, u64 *size_p) { if (*size_p >= sizeof(SecurityDescriptor)) { SecurityDescriptor *sd = (SecurityDescriptor*)descr; @@ -195,9 +195,9 @@ int read_security_data(const u8 metadata_resource[], u64 metadata_resource_len, empty_sacl_fixup(sd->descriptors[i], &sd->sizes[i]); } wimlib_assert(total_len <= 0xffffffff); - if ((total_len + 7 & ~7) != ((sd->total_length + 7) & ~7)) { + if (((total_len + 7) & ~7) != ((sd->total_length + 7) & ~7)) { ERROR("Expected security data total length = %u, but " - "calculated %u", sd->total_length, total_len); + "calculated %u", sd->total_length, (unsigned)total_len); goto out_invalid_sd; } sd->total_length = total_len; diff --git a/src/xml.c b/src/xml.c index a8fa087e..76bc1713 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1065,7 +1065,6 @@ static int calculate_dentry_statistics(struct dentry *dentry, void *arg) void xml_update_image_info(WIMStruct *w, int image) { struct image_info *image_info; - struct dentry *root; char *flags_save; DEBUG("Updating the image info for image %d", image); @@ -1140,11 +1139,8 @@ out_free_wim_info: * */ void print_image_info(const struct wim_info *wim_info, int image) { - uint i; const struct image_info *image_info; const char *desc; - int start; - int end; time_t time; char *p;