summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2023-08-25 20:56:50 (GMT)
committerGitHub <noreply@github.com>2023-08-25 20:56:50 (GMT)
commit627f7c5e026a55f176d8dfcab51633cf3b704ce6 (patch)
treeb8ef6ca645521104c25a7b5538259bb449d51c58
parent3dd60d914e762c6cf7d99646bc516015229176cd (diff)
downloadhdf5-627f7c5e026a55f176d8dfcab51633cf3b704ce6.zip
hdf5-627f7c5e026a55f176d8dfcab51633cf3b704ce6.tar.gz
hdf5-627f7c5e026a55f176d8dfcab51633cf3b704ce6.tar.bz2
Convert some H5MM calls to standard C equivalents (#2382)
* H5MM_calloc and malloc are now mapped to stdlib C calls * H5MM_memcpy now maps directly to memcpy in release builds * H5MM_memcpy is still implemented as a separate function that checks for buffer overlap when H5MM_DEBUG is defined (default w/ debug builds) * Switches many library memcpy calls to use H5MM_memcpy * Fixes a possible zero allocation in H5Olayout.c
-rw-r--r--config/cmake/HDFCompilerFlags.cmake1
-rw-r--r--configure.ac4
-rw-r--r--src/H5CS.c2
-rw-r--r--src/H5Dchunk.c8
-rw-r--r--src/H5Dmpio.c4
-rw-r--r--src/H5Dscatgath.c4
-rw-r--r--src/H5FDonion.c10
-rw-r--r--src/H5FDonion_header.c16
-rw-r--r--src/H5FDonion_history.c12
-rw-r--r--src/H5FDonion_index.c43
-rw-r--r--src/H5FDros3.c4
-rw-r--r--src/H5FDsubfiling/H5FDioc.c6
-rw-r--r--src/H5FDsubfiling/H5FDioc_threads.c2
-rw-r--r--src/H5FDsubfiling/H5FDsubfiling.c18
-rw-r--r--src/H5FL.c16
-rw-r--r--src/H5MM.c61
-rw-r--r--src/H5MMprivate.h22
-rw-r--r--src/H5Olayout.c12
-rw-r--r--src/H5RS.c6
-rw-r--r--src/H5Tinit_float.c8
-rw-r--r--src/H5Tref.c2
-rw-r--r--src/H5Tvlen.c46
-rw-r--r--src/H5encode.h9
23 files changed, 142 insertions, 174 deletions
diff --git a/config/cmake/HDFCompilerFlags.cmake b/config/cmake/HDFCompilerFlags.cmake
index 1878b9b..1dca910 100644
--- a/config/cmake/HDFCompilerFlags.cmake
+++ b/config/cmake/HDFCompilerFlags.cmake
@@ -310,6 +310,7 @@ if (HDF5_ENABLE_DEBUG_APIS)
H5F_DEBUG
H5HL_DEBUG
H5I_DEBUG
+ H5MM_DEBUG
H5O_DEBUG
H5S_DEBUG
H5T_DEBUG
diff --git a/configure.ac b/configure.ac
index c0eb47c..fadd1c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2492,8 +2492,8 @@ AC_SUBST([INTERNAL_DEBUG_OUTPUT])
## too specialized or have huge performance hits. These
## are not listed in the "all" packages list.
##
-## all_packages="AC,B,B2,D,F,FA,FL,FS,HL,I,O,S,T,Z"
-all_packages="AC,B2,CX,D,F,HL,I,O,S,T,Z"
+## all_packages="AC,B,B2,D,F,FA,FL,FS,HL,I,MM,O,S,T,Z"
+all_packages="AC,B2,CX,D,F,HL,I,MM,O,S,T,Z"
case "X-$INTERNAL_DEBUG_OUTPUT" in
X-yes|X-all)
diff --git a/src/H5CS.c b/src/H5CS.c
index d8ee8d7..203c281 100644
--- a/src/H5CS.c
+++ b/src/H5CS.c
@@ -248,7 +248,7 @@ H5CS_copy_stack(void)
/* Copy pointers on old stack to new one */
/* (Strings don't need to be duplicated, they are statically allocated) */
- memcpy(new_stack->rec, old_stack->rec, sizeof(char *) * old_stack->nused);
+ H5MM_memcpy(new_stack->rec, old_stack->rec, sizeof(char *) * old_stack->nused);
new_stack->nused = new_stack->nalloc = old_stack->nused;
/* Set the return value */
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c
index 8f34c2f..956baf3 100644
--- a/src/H5Dchunk.c
+++ b/src/H5Dchunk.c
@@ -2790,7 +2790,7 @@ H5D__chunk_read(H5D_io_info_t *io_info, H5D_dset_io_info_t *dset_info)
/* Set up contiguous I/O info object */
H5MM_memcpy(&ctg_io_info, io_info, sizeof(ctg_io_info));
- memcpy(&ctg_dset_info, dset_info, sizeof(ctg_dset_info));
+ H5MM_memcpy(&ctg_dset_info, dset_info, sizeof(ctg_dset_info));
ctg_dset_info.store = &ctg_store;
ctg_dset_info.layout_ops = *H5D_LOPS_CONTIG;
ctg_io_info.dsets_info = &ctg_dset_info;
@@ -2802,7 +2802,7 @@ H5D__chunk_read(H5D_io_info_t *io_info, H5D_dset_io_info_t *dset_info)
/* Set up compact I/O info object */
H5MM_memcpy(&cpt_io_info, io_info, sizeof(cpt_io_info));
- memcpy(&cpt_dset_info, dset_info, sizeof(cpt_dset_info));
+ H5MM_memcpy(&cpt_dset_info, dset_info, sizeof(cpt_dset_info));
cpt_dset_info.store = &cpt_store;
cpt_dset_info.layout_ops = *H5D_LOPS_COMPACT;
cpt_io_info.dsets_info = &cpt_dset_info;
@@ -2950,7 +2950,7 @@ H5D__chunk_write(H5D_io_info_t *io_info, H5D_dset_io_info_t *dset_info)
/* Set up contiguous I/O info object */
H5MM_memcpy(&ctg_io_info, io_info, sizeof(ctg_io_info));
- memcpy(&ctg_dset_info, dset_info, sizeof(ctg_dset_info));
+ H5MM_memcpy(&ctg_dset_info, dset_info, sizeof(ctg_dset_info));
ctg_dset_info.store = &ctg_store;
ctg_dset_info.layout_ops = *H5D_LOPS_CONTIG;
ctg_io_info.dsets_info = &ctg_dset_info;
@@ -2962,7 +2962,7 @@ H5D__chunk_write(H5D_io_info_t *io_info, H5D_dset_io_info_t *dset_info)
/* Set up compact I/O info object */
H5MM_memcpy(&cpt_io_info, io_info, sizeof(cpt_io_info));
- memcpy(&cpt_dset_info, dset_info, sizeof(cpt_dset_info));
+ H5MM_memcpy(&cpt_dset_info, dset_info, sizeof(cpt_dset_info));
cpt_dset_info.store = &cpt_store;
cpt_dset_info.layout_ops = *H5D_LOPS_COMPACT;
cpt_io_info.dsets_info = &cpt_dset_info;
diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c
index 82bcf02..2c4c29e 100644
--- a/src/H5Dmpio.c
+++ b/src/H5Dmpio.c
@@ -3772,7 +3772,7 @@ H5D__mpio_share_chunk_modification_data(H5D_filtered_collective_io_info_t *chunk
mod_data_p = msg_send_bufs[num_send_requests];
/* Store the chunk's index into the buffer */
- memcpy(mod_data_p, &chunk_entry->index_info.chunk_idx, sizeof(hsize_t));
+ H5MM_memcpy(mod_data_p, &chunk_entry->index_info.chunk_idx, sizeof(hsize_t));
mod_data_p += sizeof(hsize_t);
/* Serialize the chunk's file dataspace into the buffer */
@@ -4491,7 +4491,7 @@ H5D__mpio_collective_filtered_chunk_update(H5D_filtered_collective_io_info_t *ch
if (msg_ptr) {
/* Retrieve the chunk's index value */
- memcpy(&chunk_idx, msg_ptr, sizeof(hsize_t));
+ H5MM_memcpy(&chunk_idx, msg_ptr, sizeof(hsize_t));
msg_ptr += sizeof(hsize_t);
/* Find the chunk entry according to its chunk index */
diff --git a/src/H5Dscatgath.c b/src/H5Dscatgath.c
index 4516f1f..a9158bf 100644
--- a/src/H5Dscatgath.c
+++ b/src/H5Dscatgath.c
@@ -118,7 +118,7 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, const H5D_dset_io_info_t *_dset
/* Set up temporary I/O info object */
H5MM_memcpy(&tmp_io_info, _io_info, sizeof(*_io_info));
- memcpy(&tmp_dset_info, _dset_info, sizeof(*_dset_info));
+ H5MM_memcpy(&tmp_dset_info, _dset_info, sizeof(*_dset_info));
tmp_io_info.op_type = H5D_IO_OP_WRITE;
tmp_dset_info.buf.cvp = _buf;
tmp_io_info.dsets_info = &tmp_dset_info;
@@ -219,7 +219,7 @@ H5D__gather_file(const H5D_io_info_t *_io_info, const H5D_dset_io_info_t *_dset_
/* Set up temporary I/O info object */
H5MM_memcpy(&tmp_io_info, _io_info, sizeof(*_io_info));
- memcpy(&tmp_dset_info, _dset_info, sizeof(*_dset_info));
+ H5MM_memcpy(&tmp_dset_info, _dset_info, sizeof(*_dset_info));
tmp_io_info.op_type = H5D_IO_OP_READ;
tmp_dset_info.buf.vp = _buf;
tmp_io_info.dsets_info = &tmp_dset_info;
diff --git a/src/H5FDonion.c b/src/H5FDonion.c
index dcec221..a9d11e0 100644
--- a/src/H5FDonion.c
+++ b/src/H5FDonion.c
@@ -295,7 +295,7 @@ H5Pget_fapl_onion(hid_t fapl_id, H5FD_onion_fapl_info_t *fa_out)
if (NULL == (info_ptr = (const H5FD_onion_fapl_info_t *)H5P_peek_driver_info(plist)))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad VFL driver info");
- memcpy(fa_out, info_ptr, sizeof(H5FD_onion_fapl_info_t));
+ H5MM_memcpy(fa_out, info_ptr, sizeof(H5FD_onion_fapl_info_t));
done:
FUNC_LEAVE_API(ret_value)
@@ -514,7 +514,7 @@ H5FD__onion_commit_new_revision_record(H5FD_onion_t *file)
if (NULL == (new_list = H5MM_calloc((history->n_revisions + 1) * sizeof(H5FD_onion_record_loc_t))))
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to resize record pointer list");
- memcpy(new_list, history->record_locs, sizeof(H5FD_onion_record_loc_t) * history->n_revisions);
+ H5MM_memcpy(new_list, history->record_locs, sizeof(H5FD_onion_record_loc_t) * history->n_revisions);
H5MM_xfree(history->record_locs);
history->record_locs = new_list;
new_list = NULL;
@@ -980,7 +980,7 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
/* Initialize file structure fields */
- memcpy(&(file->fa), fa, sizeof(H5FD_onion_fapl_info_t));
+ H5MM_memcpy(&(file->fa), fa, sizeof(H5FD_onion_fapl_info_t));
file->header.version = H5FD_ONION_HEADER_VERSION_CURR;
file->header.page_size = file->fa.page_size; /* guarded on FAPL-set */
@@ -1523,7 +1523,7 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
if (H5FD_read(file->onion_file, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, page_buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get working file data");
/* Overlay delta from input buffer onto page buffer. */
- memcpy(page_buf + page_gap_head, buf, page_n_used);
+ H5MM_memcpy(page_buf + page_gap_head, buf, page_n_used);
write_buf = page_buf;
} /* end if partial page */
@@ -1571,7 +1571,7 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
/* Copy input buffer to temporary page buffer */
assert((page_size - page_gap_head) >= page_n_used);
- memcpy(page_buf + page_gap_head, buf, page_n_used);
+ H5MM_memcpy(page_buf + page_gap_head, buf, page_n_used);
write_buf = page_buf;
} /* end if data range does not span entire page */
diff --git a/src/H5FDonion_header.c b/src/H5FDonion_header.c
index a346ecf..55a632c 100644
--- a/src/H5FDonion_header.c
+++ b/src/H5FDonion_header.c
@@ -142,34 +142,34 @@ H5FD__onion_header_decode(unsigned char *buf, H5FD_onion_header_t *header)
ptr = buf + 5;
ui32 = 0;
- memcpy(&ui32, ptr, 3);
+ H5MM_memcpy(&ui32, ptr, 3);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, header->flags);
ptr += 3;
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, header->page_size);
ptr += 4;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT32DECODE(ui8p, header->origin_eof);
ptr += 8;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT32DECODE(ui8p, header->history_addr);
ptr += 8;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT32DECODE(ui8p, header->history_size);
ptr += 8;
sum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, header->checksum);
ptr += 4;
@@ -214,9 +214,9 @@ H5FD__onion_header_encode(H5FD_onion_header_t *header, unsigned char *buf, uint3
assert(H5FD_ONION_HEADER_VERSION_CURR == header->version);
assert(0 == (header->flags & 0xFF000000)); /* max three bits long */
- memcpy(ptr, H5FD_ONION_HEADER_SIGNATURE, 4);
+ H5MM_memcpy(ptr, H5FD_ONION_HEADER_SIGNATURE, 4);
ptr += 4;
- memcpy(ptr, (unsigned char *)&header->version, 1);
+ H5MM_memcpy(ptr, (unsigned char *)&header->version, 1);
ptr += 1;
UINT32ENCODE(ptr, header->flags);
ptr -= 1; /* truncate to three bytes */
diff --git a/src/H5FDonion_history.c b/src/H5FDonion_history.c
index e559e80..875d638 100644
--- a/src/H5FDonion_history.c
+++ b/src/H5FDonion_history.c
@@ -180,7 +180,7 @@ H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history)
ptr = buf + 8;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, n_revisions);
ptr += 8;
@@ -207,19 +207,19 @@ H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history)
uint64_t record_size;
uint64_t phys_addr;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, phys_addr);
H5_CHECKED_ASSIGN(rloc->phys_addr, haddr_t, phys_addr, uint64_t);
ptr += 8;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, record_size);
H5_CHECKED_ASSIGN(rloc->record_size, hsize_t, record_size, uint64_t);
ptr += 8;
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, rloc->checksum);
ptr += 4;
@@ -228,7 +228,7 @@ H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history)
sum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, history->checksum);
ptr += 4;
@@ -275,7 +275,7 @@ H5FD__onion_history_encode(H5FD_onion_history_t *history, unsigned char *buf, ui
assert(buf != NULL);
assert(checksum != NULL);
- memcpy(ptr, H5FD_ONION_HISTORY_SIGNATURE, 4);
+ H5MM_memcpy(ptr, H5FD_ONION_HISTORY_SIGNATURE, 4);
ptr += 4;
UINT32ENCODE(ptr, vers_u32);
UINT64ENCODE(ptr, history->n_revisions);
diff --git a/src/H5FDonion_index.c b/src/H5FDonion_index.c
index a6215ab..fae87ca 100644
--- a/src/H5FDonion_index.c
+++ b/src/H5FDonion_index.c
@@ -483,7 +483,7 @@ H5FD__onion_revision_index_insert(H5FD_onion_revision_index_t *rix, const H5FD_o
if (entry->phys_addr != node->entry_data.phys_addr) {
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "physical address mismatch");
}
- memcpy(&node->entry_data, entry, sizeof(H5FD_onion_index_entry_t));
+ H5MM_memcpy(&node->entry_data, entry, sizeof(H5FD_onion_index_entry_t));
append_dest = NULL; /* Node updated, do not append */
break;
}
@@ -496,7 +496,7 @@ H5FD__onion_revision_index_insert(H5FD_onion_revision_index_t *rix, const H5FD_o
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "cannot allocate new ash chain node");
node->version = H5FD_ONION_REVISION_INDEX_HASH_CHAIN_NODE_VERSION_CURR;
node->next = NULL;
- memcpy(&node->entry_data, entry, sizeof(H5FD_onion_index_entry_t));
+ H5MM_memcpy(&node->entry_data, entry, sizeof(H5FD_onion_index_entry_t));
*append_dest = node;
rix->n_entries++;
}
@@ -612,25 +612,25 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
ptr = buf + 8;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, record->revision_num);
ptr += 8;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, record->parent_revision_num);
ptr += 8;
- memcpy(record->time_of_creation, ptr, 16);
+ H5MM_memcpy(record->time_of_creation, ptr, 16);
ptr += 16;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, record->logical_eof);
ptr += 8;
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, page_size);
ptr += 4;
@@ -645,12 +645,12 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
record->archival_index.page_size_log2++)
;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, n_entries);
ptr += 8;
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, comment_size);
ptr += 4;
@@ -671,7 +671,7 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
for (size_t i = 0; i < n_entries; i++) {
entry = &record->archival_index.list[i];
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, entry->logical_page);
ptr += 8;
@@ -682,12 +682,12 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
entry->logical_page = entry->logical_page >> record->archival_index.page_size_log2;
- memcpy(&ui64, ptr, 8);
+ H5MM_memcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
UINT64DECODE(ui8p, entry->phys_addr);
ptr += 8;
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, sum);
ptr += 4;
@@ -706,13 +706,13 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
else {
if (record->comment == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "no comment pointer");
- memcpy(record->comment, ptr, comment_size);
+ H5MM_memcpy(record->comment, ptr, comment_size);
}
ptr += comment_size;
sum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
- memcpy(&ui32, ptr, 4);
+ H5MM_memcpy(&ui32, ptr, 4);
ui8p = (uint8_t *)&ui32;
UINT32DECODE(ui8p, record->checksum);
ptr += 4;
@@ -765,12 +765,12 @@ H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigne
page_size = (uint32_t)(1 << record->archival_index.page_size_log2);
- memcpy(ptr, H5FD_ONION_REVISION_RECORD_SIGNATURE, 4);
+ H5MM_memcpy(ptr, H5FD_ONION_REVISION_RECORD_SIGNATURE, 4);
ptr += 4;
UINT32ENCODE(ptr, vers_u32);
UINT64ENCODE(ptr, record->revision_num);
UINT64ENCODE(ptr, record->parent_revision_num);
- memcpy(ptr, record->time_of_creation, 16);
+ H5MM_memcpy(ptr, record->time_of_creation, 16);
ptr += 16;
UINT64ENCODE(ptr, record->logical_eof);
UINT32ENCODE(ptr, page_size);
@@ -798,7 +798,7 @@ H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigne
if (record->comment_size > 0) {
assert(record->comment != NULL && *record->comment != '\0');
- memcpy(ptr, record->comment, record->comment_size);
+ H5MM_memcpy(ptr, record->comment, record->comment_size);
ptr += record->comment_size;
}
@@ -876,7 +876,8 @@ H5FD__onion_merge_revision_index_into_archival_index(const H5FD_onion_revision_i
const H5FD_onion_revision_index_hash_chain_node_t *node = NULL;
for (node = rix->_hash_table[i]; node != NULL; node = node->next) {
- memcpy(&new_aix.list[new_aix.n_entries], &node->entry_data, sizeof(H5FD_onion_index_entry_t));
+ H5MM_memcpy(&new_aix.list[new_aix.n_entries], &node->entry_data,
+ sizeof(H5FD_onion_index_entry_t));
new_aix.n_entries++;
}
}
@@ -901,7 +902,7 @@ H5FD__onion_merge_revision_index_into_archival_index(const H5FD_onion_revision_i
/* Add only if page not already added from revision index */
if (H5FD__onion_archival_index_find(&new_aix, aix->list[i].logical_page, &entry) == 0) {
- memcpy(&kept_list[n_kept], &aix->list[i], sizeof(H5FD_onion_index_entry_t));
+ H5MM_memcpy(&kept_list[n_kept], &aix->list[i], sizeof(H5FD_onion_index_entry_t));
n_kept++;
}
}
@@ -914,12 +915,12 @@ H5FD__onion_merge_revision_index_into_archival_index(const H5FD_onion_revision_i
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate exact-size archival index list");
/* Copy (new) revision list entries to replacement list */
- memcpy(aix->list, new_aix.list, sizeof(H5FD_onion_index_entry_t) * new_aix.n_entries);
+ H5MM_memcpy(aix->list, new_aix.list, sizeof(H5FD_onion_index_entry_t) * new_aix.n_entries);
aix->n_entries = new_aix.n_entries;
/* Copy (old) kept archival list entries to replacement list */
if (n_kept > 0) {
- memcpy(&aix->list[aix->n_entries], kept_list, sizeof(H5FD_onion_index_entry_t) * n_kept);
+ H5MM_memcpy(&aix->list[aix->n_entries], kept_list, sizeof(H5FD_onion_index_entry_t) * n_kept);
aix->n_entries += n_kept;
}
diff --git a/src/H5FDros3.c b/src/H5FDros3.c
index c6414af..19de079 100644
--- a/src/H5FDros3.c
+++ b/src/H5FDros3.c
@@ -809,13 +809,13 @@ H5Pset_fapl_ros3_token(hid_t fapl_id, const char *token)
if (H5P_get(plist, ROS3_TOKEN_PROP_NAME, &token_src) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get token value");
- memcpy(token_src, token, HDstrlen(token) + 1);
+ H5MM_memcpy(token_src, token, HDstrlen(token) + 1);
}
else {
token_src = (char *)malloc(sizeof(char) * (H5FD_ROS3_MAX_SECRET_TOK_LEN + 1));
if (token_src == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot make space for token_src variable.");
- memcpy(token_src, token, HDstrlen(token) + 1);
+ H5MM_memcpy(token_src, token, HDstrlen(token) + 1);
if (H5P_insert(plist, ROS3_TOKEN_PROP_NAME, sizeof(char *), &token_src, NULL, NULL, NULL, NULL,
H5FD__ros3_str_token_delete, H5FD__ros3_str_token_copy, H5FD__ros3_str_token_cmp,
H5FD__ros3_str_token_close) < 0)
diff --git a/src/H5FDsubfiling/H5FDioc.c b/src/H5FDsubfiling/H5FDioc.c
index 81ad0e7..570c747 100644
--- a/src/H5FDsubfiling/H5FDioc.c
+++ b/src/H5FDsubfiling/H5FDioc.c
@@ -399,7 +399,7 @@ H5Pget_fapl_ioc(hid_t fapl_id, H5FD_ioc_config_t *config_out)
}
else {
/* Copy the IOC fapl data out */
- memcpy(config_out, config_ptr, sizeof(H5FD_ioc_config_t));
+ H5MM_memcpy(config_out, config_ptr, sizeof(H5FD_ioc_config_t));
}
done:
@@ -666,7 +666,7 @@ H5FD__ioc_fapl_copy(const void *_old_fa)
if (NULL == new_fa_ptr)
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL");
- memcpy(new_fa_ptr, old_fa_ptr, sizeof(H5FD_ioc_config_t));
+ H5MM_memcpy(new_fa_ptr, old_fa_ptr, sizeof(H5FD_ioc_config_t));
ret_value = (void *)new_fa_ptr;
@@ -790,7 +790,7 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
}
/* Fill in the file config values */
- memcpy(&file_ptr->fa, config_ptr, sizeof(H5FD_ioc_config_t));
+ H5MM_memcpy(&file_ptr->fa, config_ptr, sizeof(H5FD_ioc_config_t));
/* Fully resolve the given filepath and get its dirname */
if (H5_resolve_pathname(name, file_ptr->comm, &file_ptr->file_path) < 0)
diff --git a/src/H5FDsubfiling/H5FDioc_threads.c b/src/H5FDsubfiling/H5FDioc_threads.c
index f4da503..cb3458e 100644
--- a/src/H5FDsubfiling/H5FDioc_threads.c
+++ b/src/H5FDsubfiling/H5FDioc_threads.c
@@ -1304,7 +1304,7 @@ ioc_io_queue_add_entry(ioc_data_t *ioc_data, sf_work_request_t *wk_req_ptr)
assert(entry_ptr);
assert(entry_ptr->magic == H5FD_IOC__IO_Q_ENTRY_MAGIC);
- memcpy((void *)(&(entry_ptr->wk_req)), (const void *)wk_req_ptr, sizeof(sf_work_request_t));
+ H5MM_memcpy((void *)(&(entry_ptr->wk_req)), (const void *)wk_req_ptr, sizeof(sf_work_request_t));
/* must obtain io_queue mutex before appending */
hg_thread_mutex_lock(&ioc_data->io_queue.q_mutex);
diff --git a/src/H5FDsubfiling/H5FDsubfiling.c b/src/H5FDsubfiling/H5FDsubfiling.c
index 6a04f68..89afa01 100644
--- a/src/H5FDsubfiling/H5FDsubfiling.c
+++ b/src/H5FDsubfiling/H5FDsubfiling.c
@@ -553,7 +553,7 @@ H5Pget_fapl_subfiling(hid_t fapl_id, H5FD_subfiling_config_t *config_out)
}
else {
/* Copy the subfiling fapl data out */
- memcpy(config_out, config_ptr, sizeof(H5FD_subfiling_config_t));
+ H5MM_memcpy(config_out, config_ptr, sizeof(H5FD_subfiling_config_t));
/* Copy the driver info value */
if (H5FD__copy_plist(config_ptr->ioc_fapl_id, &(config_out->ioc_fapl_id)) < 0)
@@ -811,7 +811,7 @@ H5FD__subfiling_sb_encode(H5FD_t *_file, char *name, unsigned char *buf)
/* Encode config file prefix string */
if (sf_context->config_file_prefix) {
- memcpy(p, sf_context->config_file_prefix, prefix_len);
+ H5MM_memcpy(p, sf_context->config_file_prefix, prefix_len);
p += prefix_len;
}
@@ -826,7 +826,7 @@ H5FD__subfiling_sb_encode(H5FD_t *_file, char *name, unsigned char *buf)
"unable to encode IOC VFD's superblock information");
/* Copy the IOC VFD's name into our buffer */
- memcpy(p, ioc_name, 9);
+ H5MM_memcpy(p, ioc_name, 9);
}
done:
@@ -893,9 +893,9 @@ H5FD__subfiling_sb_decode(H5FD_t *_file, const char *name, const unsigned char *
H5_SUBFILING_GOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL,
"can't allocate space for config file prefix string");
- memcpy(sf_context->config_file_prefix, p, tmpu64);
+ H5MM_memcpy(sf_context->config_file_prefix, p, tmpu64);
- /* Just in case.. */
+ /* Just in case... */
sf_context->config_file_prefix[tmpu64 - 1] = '\0';
}
@@ -905,7 +905,7 @@ H5FD__subfiling_sb_decode(H5FD_t *_file, const char *name, const unsigned char *
if (file->sf_file) {
char ioc_name[9];
- memcpy(ioc_name, p, 9);
+ H5MM_memcpy(ioc_name, p, 9);
p += 9;
if (H5FD_sb_load(file->sf_file, ioc_name, p) < 0)
@@ -960,7 +960,7 @@ H5FD__subfiling_fapl_get(H5FD_t *_file)
}
/* Copy the fields of the structure */
- memcpy(fa, &(file->fa), sizeof(H5FD_subfiling_config_t));
+ H5MM_memcpy(fa, &(file->fa), sizeof(H5FD_subfiling_config_t));
/* Copy the driver info value */
if (H5FD__copy_plist(file->fa.ioc_fapl_id, &(fa->ioc_fapl_id)) < 0)
@@ -1036,7 +1036,7 @@ H5FD__subfiling_fapl_copy(const void *_old_fa)
H5_SUBFILING_GOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
}
- memcpy(new_fa, old_fa, sizeof(H5FD_subfiling_config_t));
+ H5MM_memcpy(new_fa, old_fa, sizeof(H5FD_subfiling_config_t));
if (H5FD__copy_plist(old_fa->ioc_fapl_id, &(new_fa->ioc_fapl_id)) < 0)
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy the IOC FAPL");
@@ -1169,7 +1169,7 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma
config_ptr = &default_config;
}
- memcpy(&file_ptr->fa, config_ptr, sizeof(H5FD_subfiling_config_t));
+ H5MM_memcpy(&file_ptr->fa, config_ptr, sizeof(H5FD_subfiling_config_t));
if (H5FD__copy_plist(config_ptr->ioc_fapl_id, &(file_ptr->fa.ioc_fapl_id)) < 0) {
file_ptr->fa.ioc_fapl_id = H5I_INVALID_HID;
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't copy FAPL");
diff --git a/src/H5FL.c b/src/H5FL.c
index ec952b7..5ed6430 100644
--- a/src/H5FL.c
+++ b/src/H5FL.c
@@ -957,7 +957,7 @@ H5FL_blk_free(H5FL_blk_head_t *head, void *block)
unsigned char *block_ptr = ((unsigned char *)block) - sizeof(H5FL_track_t);
H5FL_track_t trk;
- memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
+ H5MM_memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
/* Free tracking information about the allocation location */
H5CS_close_stack(trk.stack);
@@ -979,7 +979,7 @@ H5FL_blk_free(H5FL_blk_head_t *head, void *block)
trk.next->prev = trk.prev;
} /* end else */
- memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
+ H5MM_memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
}
#endif /* H5FL_TRACK */
@@ -1079,7 +1079,7 @@ H5FL_blk_realloc(H5FL_blk_head_t *head, void *block, size_t new_size H5FL_TRACK_
unsigned char *block_ptr = ((unsigned char *)block) - sizeof(H5FL_track_t);
H5FL_track_t trk;
- memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
+ H5MM_memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
/* Release previous tracking information */
H5CS_close_stack(trk.stack);
@@ -1099,7 +1099,7 @@ H5FL_blk_realloc(H5FL_blk_head_t *head, void *block, size_t new_size H5FL_TRACK_
trk.func = call_func;
trk.line = call_line;
- memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
+ H5MM_memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
}
#endif /* H5FL_TRACK */
ret_value = block;
@@ -1380,7 +1380,7 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
unsigned char *block_ptr = ((unsigned char *)obj) - sizeof(H5FL_track_t);
H5FL_track_t trk;
- memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
+ H5MM_memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
/* Free tracking information about the allocation location */
H5CS_close_stack(trk.stack);
@@ -1402,7 +1402,7 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
trk.next->prev = trk.prev;
} /* end else */
- memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
+ H5MM_memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
}
#endif
@@ -1631,7 +1631,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void *obj, size_t new_elem H5FL_TRACK_PA
unsigned char *block_ptr = ((unsigned char *)obj) - sizeof(H5FL_track_t);
H5FL_track_t trk;
- memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
+ H5MM_memcpy(&trk, block_ptr, sizeof(H5FL_track_t));
/* Release previous tracking information */
H5CS_close_stack(trk.stack);
@@ -1651,7 +1651,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void *obj, size_t new_elem H5FL_TRACK_PA
trk.func = call_func;
trk.line = call_line;
- memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
+ H5MM_memcpy(block_ptr, &trk, sizeof(H5FL_track_t));
#endif
ret_value = obj;
}
diff --git a/src/H5MM.c b/src/H5MM.c
index 609f946..d48ec80 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -55,63 +55,6 @@
/*******************/
/*-------------------------------------------------------------------------
- * Function: H5MM_malloc
- *
- * Purpose: Similar to the C89 version of malloc().
- *
- * On size of 0, we return a NULL pointer instead of the
- * standard-allowed 'special' pointer since that's more
- * difficult to check as a return value. This is still
- * considered an error condition since allocations of zero
- * bytes usually indicate problems.
- *
- * Return: Success: Pointer to new memory
- * Failure: NULL
- *-------------------------------------------------------------------------
- */
-void *
-H5MM_malloc(size_t size)
-{
- void *ret_value = NULL;
-
- /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- ret_value = malloc(size);
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MM_malloc() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MM_calloc
- *
- * Purpose: Similar to the C89 version of calloc(), except this
- * routine just takes a 'size' parameter.
- *
- * On size of 0, we return a NULL pointer instead of the
- * standard-allowed 'special' pointer since that's more
- * difficult to check as a return value. This is still
- * considered an error condition since allocations of zero
- * bytes usually indicate problems.
- *
- * Return: Success: Pointer to new memory
- * Failure: NULL
- *-------------------------------------------------------------------------
- */
-void *
-H5MM_calloc(size_t size)
-{
- void *ret_value = NULL;
-
- /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- ret_value = calloc(1, size);
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MM_calloc() */
-
-/*-------------------------------------------------------------------------
* Function: H5MM_realloc
*
* Purpose: Similar semantics as C89's realloc(). Specifically, the
@@ -283,6 +226,8 @@ H5MM_xfree_const(const void *mem)
FUNC_LEAVE_NOAPI(NULL)
} /* end H5MM_xfree_const() */
+#ifdef H5MM_DEBUG
+
/*-------------------------------------------------------------------------
* Function: H5MM_memcpy
*
@@ -313,3 +258,5 @@ H5MM_memcpy(void *dest, const void *src, size_t n)
FUNC_LEAVE_NOAPI(ret)
} /* end H5MM_memcpy() */
+
+#endif /* H5MM_DEBUG */
diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h
index f94a433..39bba2c 100644
--- a/src/H5MMprivate.h
+++ b/src/H5MMprivate.h
@@ -14,7 +14,7 @@
*
* Created: H5MMprivate.h
*
- * Purpose: Private header for memory management.
+ * Purpose: Private header for memory management
*
*-------------------------------------------------------------------------
*/
@@ -26,19 +26,33 @@
/* Private headers needed by this file */
#include "H5private.h"
-#define H5MM_free(Z) free(Z)
+/* Uncomment this macro to enable some extra memory checks
+ *
+ * This can also be defined at configure time, which we do in debug builds
+ * by default.
+ */
+/* #define H5MM_DEBUG */
+
+#define H5MM_calloc(Z) calloc(1, Z)
+#define H5MM_free(Z) free(Z)
+#define H5MM_malloc(Z) malloc(Z)
+
+#ifndef H5MM_DEBUG
+#define H5MM_memcpy(D, S, N) memcpy(D, S, N)
+#endif /* !H5MM_DEBUG */
/*
* Library prototypes...
*/
-H5_DLL void *H5MM_malloc(size_t size) H5_ATTR_MALLOC;
-H5_DLL void *H5MM_calloc(size_t size) H5_ATTR_MALLOC;
H5_DLL void *H5MM_realloc(void *mem, size_t size);
H5_DLL char *H5MM_xstrdup(const char *s) H5_ATTR_MALLOC;
H5_DLL char *H5MM_strdup(const char *s) H5_ATTR_MALLOC;
H5_DLL char *H5MM_strndup(const char *s, size_t n) H5_ATTR_MALLOC;
H5_DLL void *H5MM_xfree(void *mem);
H5_DLL void *H5MM_xfree_const(const void *mem);
+
+#ifdef H5MM_DEBUG
H5_DLL void *H5MM_memcpy(void *dest, const void *src, size_t n);
+#endif
#endif /* H5MMprivate_H */
diff --git a/src/H5Olayout.c b/src/H5Olayout.c
index 4ee2f82..f725b5c 100644
--- a/src/H5Olayout.c
+++ b/src/H5Olayout.c
@@ -582,9 +582,15 @@ H5O__layout_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNU
H5F_DECODE_LENGTH(f, heap_block_p, tmp_hsize);
/* Allocate entry list */
- if (NULL == (mesg->storage.u.virt.list = (H5O_storage_virtual_ent_t *)H5MM_calloc(
- (size_t)tmp_hsize * sizeof(H5O_storage_virtual_ent_t))))
- HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "unable to allocate heap block");
+ if (tmp_hsize > 0) {
+ if (NULL == (mesg->storage.u.virt.list = (H5O_storage_virtual_ent_t *)H5MM_calloc(
+ (size_t)tmp_hsize * sizeof(H5O_storage_virtual_ent_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "unable to allocate heap block");
+ }
+ else {
+ /* Avoid zero-size allocation */
+ mesg->storage.u.virt.list = NULL;
+ }
mesg->storage.u.virt.list_nalloc = (size_t)tmp_hsize;
mesg->storage.u.virt.list_nused = (size_t)tmp_hsize;
diff --git a/src/H5RS.c b/src/H5RS.c
index 0bf40b1..1ad22f3 100644
--- a/src/H5RS.c
+++ b/src/H5RS.c
@@ -124,7 +124,7 @@ H5RS__xstrdup(H5RS_str_t *rs, const char *s)
if (NULL == (rs->s = (char *)H5FL_BLK_MALLOC(str_buf, rs->max)))
HGOTO_ERROR(H5E_RS, H5E_CANTALLOC, FAIL, "memory allocation failed");
if (len)
- memcpy(rs->s, s, len);
+ H5MM_memcpy(rs->s, s, len);
rs->end = rs->s + len;
*rs->end = '\0';
rs->len = len;
@@ -430,7 +430,7 @@ H5RS_acat(H5RS_str_t *rs, const char *s)
HGOTO_ERROR(H5E_RS, H5E_CANTRESIZE, FAIL, "can't resize ref-counted string buffer");
/* Append the string */
- memcpy(rs->end, s, len);
+ H5MM_memcpy(rs->end, s, len);
rs->end += len;
*rs->end = '\0';
rs->len += len;
@@ -479,7 +479,7 @@ H5RS_ancat(H5RS_str_t *rs, const char *s, size_t n)
HGOTO_ERROR(H5E_RS, H5E_CANTRESIZE, FAIL, "can't resize ref-counted string buffer");
/* Append the string */
- memcpy(rs->end, s, n);
+ H5MM_memcpy(rs->end, s, n);
rs->end += n;
*rs->end = '\0';
rs->len += n;
diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c
index efab5b6..3a8c0bd 100644
--- a/src/H5Tinit_float.c
+++ b/src/H5Tinit_float.c
@@ -79,11 +79,11 @@
* and interfere with detection of the various properties below unless we \
* know to ignore them. */ \
_v1 = (TYPE)4.0L; \
- memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \
+ H5MM_memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \
for (_i = 0; _i < (int)sizeof(TYPE); _i++) \
for (_byte_mask = (unsigned char)1; _byte_mask; _byte_mask = (unsigned char)(_byte_mask << 1)) { \
_buf1[_i] ^= _byte_mask; \
- memcpy((void *)&_v2, (const void *)_buf1, sizeof(TYPE)); \
+ H5MM_memcpy((void *)&_v2, (const void *)_buf1, sizeof(TYPE)); \
H5_GCC_CLANG_DIAG_OFF("float-equal") \
if (_v1 != _v2) \
_pad_mask[_i] |= _byte_mask; \
@@ -96,8 +96,8 @@
_v3 = _v1; \
_v1 += _v2; \
_v2 /= (TYPE)256.0L; \
- memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \
- memcpy(_buf3, (const void *)&_v3, sizeof(TYPE)); \
+ H5MM_memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \
+ H5MM_memcpy(_buf3, (const void *)&_v3, sizeof(TYPE)); \
_j = H5T__byte_cmp(sizeof(TYPE), _buf3, _buf1, _pad_mask); \
if (_j >= 0) { \
INFO.perm[_i] = _j; \
diff --git a/src/H5Tref.c b/src/H5Tref.c
index ddc73ac..0e6d6dd 100644
--- a/src/H5Tref.c
+++ b/src/H5Tref.c
@@ -737,7 +737,7 @@ H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size
} /* end if */
/* Set output info */
- memcpy(dst_ref, &tmp_ref, sizeof(tmp_ref));
+ H5MM_memcpy(dst_ref, &tmp_ref, sizeof(tmp_ref));
done:
if ((file_id != H5I_INVALID_HID) && (H5I_dec_ref(file_id) < 0))
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c
index 87f0600..ac5d3c0 100644
--- a/src/H5Tvlen.c
+++ b/src/H5Tvlen.c
@@ -360,14 +360,11 @@ H5T__vlen_mem_seq_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, si
FUNC_ENTER_PACKAGE_NOERR
- /* Check parameter */
assert(_vl);
assert(len);
- /* Copy to ensure correct alignment. memcpy is best here because
- * it optimizes to fast code.
- */
- memcpy(&vl, _vl, sizeof(hvl_t));
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&vl, _vl, sizeof(hvl_t));
*len = vl.len;
@@ -390,10 +387,10 @@ H5T__vlen_mem_seq_getptr(void *_vl)
FUNC_ENTER_PACKAGE_NOERR
- /* check parameters, return result */
assert(_vl);
- /* Copy to ensure correct alignment. */
- memcpy(&vl, _vl, sizeof(hvl_t));
+
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&vl, _vl, sizeof(hvl_t));
FUNC_LEAVE_NOAPI(vl.p)
} /* end H5T__vlen_mem_seq_getptr() */
@@ -414,11 +411,10 @@ H5T__vlen_mem_seq_isnull(const H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, hb
FUNC_ENTER_PACKAGE_NOERR
- /* Check parameters */
assert(_vl);
- /* Copy to ensure correct alignment. */
- memcpy(&vl, _vl, sizeof(hvl_t));
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&vl, _vl, sizeof(hvl_t));
*isnull = ((vl.len == 0 || vl.p == NULL) ? TRUE : FALSE);
@@ -470,11 +466,11 @@ H5T__vlen_mem_seq_read(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void *buf,
FUNC_ENTER_PACKAGE_NOERR
- /* check parameters, copy data */
assert(buf);
assert(_vl);
- /* Copy to ensure correct alignment. */
- memcpy(&vl, _vl, sizeof(hvl_t));
+
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&vl, _vl, sizeof(hvl_t));
assert(vl.p);
H5MM_memcpy(buf, vl.p, len);
@@ -549,11 +545,10 @@ H5T__vlen_mem_str_getlen(H5VL_object_t H5_ATTR_UNUSED *file, const void *_vl, si
FUNC_ENTER_PACKAGE_NOERR
- /* check parameters */
assert(_vl);
- /* Copy to ensure correct alignment. */
- memcpy(&s, _vl, sizeof(char *));
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&s, _vl, sizeof(char *));
*len = HDstrlen(s);
@@ -576,10 +571,10 @@ H5T__vlen_mem_str_getptr(void *_vl)
FUNC_ENTER_PACKAGE_NOERR
- /* check parameters */
assert(_vl);
- /* Copy to ensure correct alignment. */
- memcpy(&s, _vl, sizeof(char *));
+
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&s, _vl, sizeof(char *));
FUNC_LEAVE_NOAPI(s)
} /* end H5T__vlen_mem_str_getptr() */
@@ -600,8 +595,8 @@ H5T__vlen_mem_str_isnull(const H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, hb
FUNC_ENTER_PACKAGE_NOERR
- /* Copy to ensure correct alignment. */
- memcpy(&s, _vl, sizeof(char *));
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&s, _vl, sizeof(char *));
*isnull = (s == NULL ? TRUE : FALSE);
@@ -647,14 +642,13 @@ H5T__vlen_mem_str_read(H5VL_object_t H5_ATTR_UNUSED *file, void *_vl, void *buf,
FUNC_ENTER_PACKAGE_NOERR
if (len > 0) {
- /* check parameters */
assert(buf);
assert(_vl);
- /* Copy to ensure correct alignment. */
- memcpy(&s, _vl, sizeof(char *));
+ /* Copy to ensure correct alignment */
+ H5MM_memcpy(&s, _vl, sizeof(char *));
H5MM_memcpy(buf, s, len);
- } /* end if */
+ }
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5T__vlen_mem_str_read() */
diff --git a/src/H5encode.h b/src/H5encode.h
index a9172ff..5be75d5 100644
--- a/src/H5encode.h
+++ b/src/H5encode.h
@@ -17,6 +17,11 @@
#ifndef H5encode_H
#define H5encode_H
+/***********/
+/* Headers */
+/***********/
+#include "H5MMprivate.h" /* Memory management */
+
/**************************/
/* Library Private Macros */
/**************************/
@@ -128,7 +133,7 @@
\
HDcompile_assert(sizeof(double) == 8); \
HDcompile_assert(sizeof(double) == sizeof(uint64_t)); \
- memcpy(&_n, &n, sizeof(double)); \
+ H5MM_memcpy(&_n, &n, sizeof(double)); \
for (_u = 0; _u < sizeof(uint64_t); _u++, _n >>= 8) \
*_p++ = (uint8_t)(_n & 0xff); \
(p) = (uint8_t *)(p) + 8; \
@@ -245,7 +250,7 @@
(p) += 8; \
for (_u = 0; _u < sizeof(uint64_t); _u++) \
_n = (_n << 8) | *(--p); \
- memcpy(&(n), &_n, sizeof(double)); \
+ H5MM_memcpy(&(n), &_n, sizeof(double)); \
(p) += 8; \
} while (0)