]> wimlib.net Git - wimlib/blobdiff - src/registry.c
configure.ac: generate version number from git commit and tags
[wimlib] / src / registry.c
index 36ecdd39e231e3f7fe5fd24e4418853cbbce4245..0f753e8c7de0b6bd58bc225f8c7eb5f7a420e88d 100644 (file)
@@ -193,16 +193,16 @@ get_cell_pointer(const struct regf *regf, le32 offset, size_t wanted_size)
        u32 total = le32_to_cpu(regf->total_hbin_size);
        u32 offs = le32_to_cpu(offset);
        const struct cell *cell;
-       s32 actual_size;
+       u32 actual_size;
 
        if ((offs > total) || (offs & 7) || (wanted_size > total - offs))
                return NULL;
 
        cell = (const struct cell *)&regf->hbin_area[offs];
-       actual_size = le32_to_cpu(cell->size);
-       if (actual_size >= 0) /* Cell not in use?  */
+       actual_size = -le32_to_cpu(cell->size);
+       if (actual_size > INT32_MAX) /* Cell unused, or size was INT32_MIN?  */
                return NULL;
-       if (wanted_size > -actual_size) /* Cell too small?  */
+       if (wanted_size > actual_size) /* Cell too small?  */
                return NULL;
        return cell;
 }
@@ -243,7 +243,7 @@ iterate_subkeys_recursive(const struct regf *regf, le32 subkey_list_offset,
        unsigned num_offsets;
        size_t extra_size;
        unsigned increment;
-       const le32 *p;
+       size_t i = 0;
        enum hive_status status;
 
        if (stats->levels_remaining == 0 || stats->subkey_lists_remaining == 0)
@@ -270,8 +270,6 @@ iterate_subkeys_recursive(const struct regf *regf, le32 subkey_list_offset,
                             sizeof(struct subkey_list) + extra_size))
                return HIVE_CORRUPT;
 
-       p = list->elements;
-
        switch (list->base.magic) {
        case LF_MAGIC:
        case LH_MAGIC:
@@ -283,18 +281,20 @@ iterate_subkeys_recursive(const struct regf *regf, le32 subkey_list_offset,
                while (num_offsets--) {
                        const struct nk *sub_nk;
 
-                       sub_nk = get_cell_pointer(regf, *p, sizeof(struct nk));
+                       sub_nk = get_cell_pointer(regf, list->elements[i],
+                                                 sizeof(struct nk));
                        if (!sub_nk || sub_nk->base.magic != NK_MAGIC)
                                return HIVE_CORRUPT;
 
-                       if (!revalidate_cell(regf, *p, sizeof(struct nk) +
+                       if (!revalidate_cell(regf, list->elements[i],
+                                            sizeof(struct nk) +
                                                le16_to_cpu(sub_nk->name_size)))
                                return HIVE_CORRUPT;
 
                        status = (*cb)(sub_nk, cb_ctx);
                        if (status != HIVE_OK)
                                return status;
-                       p += increment;
+                       i += increment;
                }
                return HIVE_OK;
        case RI_MAGIC:
@@ -302,8 +302,9 @@ iterate_subkeys_recursive(const struct regf *regf, le32 subkey_list_offset,
                status = HIVE_OK;
                stats->levels_remaining--;
                while (num_offsets--) {
-                       status = iterate_subkeys_recursive(regf, *p++,
-                                                          cb, cb_ctx, stats);
+                       status = iterate_subkeys_recursive(regf,
+                                               list->elements[i++],
+                                               cb, cb_ctx, stats);
                        if (status != HIVE_OK)
                                break;
                }
@@ -353,7 +354,7 @@ lookup_subkey_cb(const struct nk *sub_nk, void *_ctx)
 
        if (names_equal(ctx->key_name, ctx->key_name_nchars,
                        sub_nk->name, le16_to_cpu(sub_nk->name_size),
-                       (sub_nk->flags & NK_COMPRESSED_NAME)))
+                       (sub_nk->flags & NK_COMPRESSED_NAME) != 0))
        {
                ctx->result = sub_nk;
                return HIVE_ITERATION_STOPPED;
@@ -489,7 +490,7 @@ lookup_value(const struct regf *regf, const tchar *key_name,
 
                if (names_equal(value_uname, value_uname_nchars,
                                vk->name, name_size,
-                                (vk->flags & VK_COMPRESSED_NAME)))
+                               (vk->flags & VK_COMPRESSED_NAME) != 0))
                {
                        *vk_ret = vk;
                        status = HIVE_OK;
@@ -681,12 +682,11 @@ append_subkey_name(const struct nk *sub_nk, void *_next_subkey_p)
                        subkey[i] = sub_nk->name[i];
                subkey[name_size] = '\0';
        } else {
-               size_t dummy;
                enum hive_status status;
 
                status = translate_wimlib_error(
                        utf16le_to_tstr((utf16lechar *)sub_nk->name,
-                                       name_size, &subkey, &dummy));
+                                       name_size, &subkey, NULL));
                if (status != HIVE_OK)
                        return status;
        }