Skip to content

Commit

Permalink
block/vpc: Use sizeof() instead of 1024 for dynamic header size
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201217162003.1102738-7-armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Markus Armbruster authored and kevmw committed Dec 18, 2020
1 parent e326f07 commit 3d6101a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions block/vpc.c
Expand Up @@ -344,7 +344,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,

if (disk_type == VHD_DYNAMIC) {
ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset),
&dyndisk_header, 1024);
&dyndisk_header, sizeof(dyndisk_header));
if (ret < 0) {
error_setg(errp, "Error reading dynamic VHD header");
goto fail;
Expand Down Expand Up @@ -858,7 +858,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
}

/* Prepare the Dynamic Disk Header */
memset(&dyndisk_header, 0, 1024);
memset(&dyndisk_header, 0, sizeof(dyndisk_header));

memcpy(dyndisk_header.magic, "cxsparse", 8);

Expand All @@ -872,12 +872,13 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
dyndisk_header.block_size = cpu_to_be32(block_size);
dyndisk_header.max_table_entries = cpu_to_be32(num_bat_entries);

dyndisk_header.checksum = cpu_to_be32(vpc_checksum(&dyndisk_header, 1024));
dyndisk_header.checksum = cpu_to_be32(
vpc_checksum(&dyndisk_header, sizeof(dyndisk_header)));

/* Write the header */
offset = 512;

ret = blk_pwrite(blk, offset, &dyndisk_header, 1024, 0);
ret = blk_pwrite(blk, offset, &dyndisk_header, sizeof(dyndisk_header), 0);
if (ret < 0) {
goto fail;
}
Expand Down

0 comments on commit 3d6101a

Please sign in to comment.