From d1e8f96a994bba76d861c0af026aabcac5808160 Mon Sep 17 00:00:00 2001 From: sards3 Date: Fri, 28 Dec 2018 02:00:28 -0600 Subject: [PATCH 1/2] Fix bug in vhd_read_sectors(). vhd_read_sectors() was using the wrong buffer pointer. After fixing it, reading/writing VHD_DIFF images seem to work in my limited testing. (I only tested VHD_DIFFs with VHD_FIXED parents). I also initialized some more uninitialized pointers in vhd_read_file() and vhd_create_file(). --- minivhd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/minivhd.c b/minivhd.c index 154de81..67cbcd0 100644 --- a/minivhd.c +++ b/minivhd.c @@ -235,6 +235,10 @@ VHDError vhd_read_file(FILE *f, VHDMeta *vhdm, const char *path) { /* Don't want a pointer to who knows where... */ vhdm->sparse_bat_arr = NULL; + vhdm->sparse_bitmap_arr = NULL; + vhdm->parent.f = NULL; + vhdm->parent.meta = NULL; + vhd_raw_foot_to_meta(vhdm); if (vhdm->type == VHD_DYNAMIC || vhdm->type == VHD_DIFF) { @@ -289,6 +293,11 @@ void vhd_create_file(FILE *f, VHDMeta *vhdm, int cyl, int heads, int spt, VHDTyp vhdm->sparse_bat_offset = VHD_FOOTER_SZ + VHD_SPARSE_HEAD_SZ; vhdm->sparse_block_sz = VHD_DEF_BLOCK_SZ; vhdm->sparse_max_bat = vhdm->curr_size / vhdm->sparse_block_sz; + vhdm->sparse_bat_arr = NULL; + vhdm->sparse_bitmap_arr = NULL; + vhdm->parent.f = NULL; + vhdm->parent.meta = NULL; + if (vhdm->curr_size % vhdm->sparse_block_sz != 0) { vhdm->sparse_max_bat += 1; @@ -619,7 +628,7 @@ int vhd_read_sectors(VHDMeta *vhdm, FILE *f, int offset, int nr_sectors, void *b { uint64_t addr = (uint64_t)s * VHD_SECTOR_SZ; fseeko64(curr_f, addr, SEEK_SET); - fread(buffer, VHD_SECTOR_SZ, 1, curr_f); + fread(buff_ptr, VHD_SECTOR_SZ, 1, curr_f); } else { From c52ec9e9debec841012dc94acb04ea289fa3ee63 Mon Sep 17 00:00:00 2001 From: sards3 Date: Fri, 28 Dec 2018 02:05:38 -0600 Subject: [PATCH 2/2] Fix some tabs/spaces whitespace issues. --- minivhd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/minivhd.c b/minivhd.c index 67cbcd0..1899939 100644 --- a/minivhd.c +++ b/minivhd.c @@ -236,8 +236,8 @@ VHDError vhd_read_file(FILE *f, VHDMeta *vhdm, const char *path) /* Don't want a pointer to who knows where... */ vhdm->sparse_bat_arr = NULL; vhdm->sparse_bitmap_arr = NULL; - vhdm->parent.f = NULL; - vhdm->parent.meta = NULL; + vhdm->parent.f = NULL; + vhdm->parent.meta = NULL; vhd_raw_foot_to_meta(vhdm); if (vhdm->type == VHD_DYNAMIC || vhdm->type == VHD_DIFF) @@ -294,9 +294,9 @@ void vhd_create_file(FILE *f, VHDMeta *vhdm, int cyl, int heads, int spt, VHDTyp vhdm->sparse_block_sz = VHD_DEF_BLOCK_SZ; vhdm->sparse_max_bat = vhdm->curr_size / vhdm->sparse_block_sz; vhdm->sparse_bat_arr = NULL; - vhdm->sparse_bitmap_arr = NULL; - vhdm->parent.f = NULL; - vhdm->parent.meta = NULL; + vhdm->sparse_bitmap_arr = NULL; + vhdm->parent.f = NULL; + vhdm->parent.meta = NULL; if (vhdm->curr_size % vhdm->sparse_block_sz != 0) {