Don't generate GUID in wimlib_create_new_wim()
authorEric Biggers <ebiggers3@gmail.com>
Sun, 15 Jan 2017 01:00:13 +0000 (17:00 -0800)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 15 Jan 2017 01:10:26 +0000 (17:10 -0800)
It's not necessary to generate a GUID in wimlib_create_new_wim() because
one is generated later by wimlib_write(), and nothing seems to assume
that a WIMStruct not yet backed by a file has a valid GUID.  This saves
a call to get_random_bytes().  Also remove some unnecessary
initializations to 0.

src/wim.c

index 937b834..ec345a9 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -172,31 +172,25 @@ wimlib_create_new_wim(enum wimlib_compression_type ctype, WIMStruct **wim_ret)
        if (!wim)
                return WIMLIB_ERR_NOMEM;
 
        if (!wim)
                return WIMLIB_ERR_NOMEM;
 
-       wim->xml_info = xml_new_info_struct();
-       wim->blob_table = new_blob_table(64);
-       if (!wim->xml_info || !wim->blob_table) {
-               wimlib_free(wim);
-               return WIMLIB_ERR_NOMEM;
-       }
-
-       /* Fill in wim->hdr with default values  */
+       /* Fill in wim->hdr with default values */
        wim->hdr.magic = WIM_MAGIC;
        wim->hdr.wim_version = WIM_VERSION_DEFAULT;
        wim->hdr.magic = WIM_MAGIC;
        wim->hdr.wim_version = WIM_VERSION_DEFAULT;
-       wim->hdr.flags = 0;
-       wim->hdr.chunk_size = 0;
-       generate_guid(wim->hdr.guid);
        wim->hdr.part_number = 1;
        wim->hdr.total_parts = 1;
        wim->hdr.part_number = 1;
        wim->hdr.total_parts = 1;
-       wim->hdr.image_count = 0;
-       wim->hdr.boot_idx = 0;
-
        wim->compression_type = WIMLIB_COMPRESSION_TYPE_NONE;
        wim->compression_type = WIMLIB_COMPRESSION_TYPE_NONE;
-       wim->chunk_size = wim->hdr.chunk_size;
 
 
-       /* Set the output compression type  */
+       /* Set the output compression type */
        wim->out_compression_type = ctype;
        wim->out_chunk_size = wim_default_nonsolid_chunk_size(ctype);
 
        wim->out_compression_type = ctype;
        wim->out_chunk_size = wim_default_nonsolid_chunk_size(ctype);
 
+       /* Allocate an empty XML info and blob table */
+       wim->xml_info = xml_new_info_struct();
+       wim->blob_table = new_blob_table(64);
+       if (!wim->xml_info || !wim->blob_table) {
+               wimlib_free(wim);
+               return WIMLIB_ERR_NOMEM;
+       }
+
        *wim_ret = wim;
        return 0;
 }
        *wim_ret = wim;
        return 0;
 }