Skip to content

Commit

Permalink
Fix valgrind warning about write of uninitialized bytes (#3389)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF authored Aug 18, 2023
1 parent 71d98e0 commit 31f4d5a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/H5FScache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,9 @@ H5FS__cache_sinfo_pre_serialize(H5F_t *f, void *_thing, haddr_t addr, size_t H5_
static herr_t
H5FS__cache_sinfo_serialize(const H5F_t *f, void *_image, size_t len, void *_thing)
{
H5FS_sinfo_t *sinfo = (H5FS_sinfo_t *)_thing; /* Pointer to the object */
H5FS_iter_ud_t udata; /* User data for callbacks */
H5FS_sinfo_t *sinfo = (H5FS_sinfo_t *)_thing; /* Pointer to the object */
H5FS_iter_ud_t udata; /* User data for callbacks */
ptrdiff_t gap_size;
uint8_t *image = (uint8_t *)_image; /* Pointer into raw data buffer */
uint8_t *chksum_image = NULL; /* Points to chksum location */
uint32_t metadata_chksum; /* Computed metadata checksum value */
Expand Down Expand Up @@ -1231,7 +1232,17 @@ H5FS__cache_sinfo_serialize(const H5F_t *f, void *_image, size_t len, void *_thi
/* Compute checksum */

/* There may be empty space between entries and chksum */
chksum_image = (uint8_t *)(_image) + len - H5FS_SIZEOF_CHKSUM;
chksum_image = (uint8_t *)(_image) + len - H5FS_SIZEOF_CHKSUM;

/*
* If there is any empty space between the entries and
* checksum, make sure that the space is initialized
* before serializing it
*/
gap_size = chksum_image - image;
if (gap_size > 0)
memset(image, 0, (size_t)gap_size);

metadata_chksum = H5_checksum_metadata(_image, (size_t)(chksum_image - (uint8_t *)_image), 0);
/* Metadata checksum */
UINT32ENCODE(chksum_image, metadata_chksum);
Expand Down

0 comments on commit 31f4d5a

Please sign in to comment.