diff options
author | Sean McBride <sean@rogue-research.com> | 2021-05-03 15:22:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 15:22:53 (GMT) |
commit | 3899e090dfd2e88b4a1929e304df835fd7a3d316 (patch) | |
tree | 449a2f35e1efe2d8e19adcefd76d85c0830197fc /tools/src/h5repack | |
parent | 44db310d8d45d7d639b5b7745636d1a58555d89a (diff) | |
download | hdf5-3899e090dfd2e88b4a1929e304df835fd7a3d316.zip hdf5-3899e090dfd2e88b4a1929e304df835fd7a3d316.tar.gz hdf5-3899e090dfd2e88b4a1929e304df835fd7a3d316.tar.bz2 |
Ubsan fixes (#498)
* Fixed use of null pointer identified by UBSan
UBSan warned:
runtime error: member access within null pointer of type 'named_dt_t' (aka 'struct named_dt_t')
with these two tests:
H5REPACK-committed_dt_DFF
H5REPACK-committed_dt
Reformulated per @gnuoyd suggestion.
* Fixed undefined float -> unsigned char conversion in HL_test_image
* Removed dead skip_overflow_tests_g global
The global `skip_overflow_tests_g` was being set but never read.
* Don't treat 2d array as 1d array, fixing UBSan complaint in `CPP_testhdf5`
* Committing clang-format changes
* Remove extra ']' in line 730.
* Committing clang-format changes
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Larry Knox <lrknox@hdfgroup.org>
Diffstat (limited to 'tools/src/h5repack')
-rw-r--r-- | tools/src/h5repack/h5repack.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c index 7bcca8f..7cad36b 100644 --- a/tools/src/h5repack/h5repack.c +++ b/tools/src/h5repack/h5repack.c @@ -225,9 +225,9 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, trav_table_t *travt, pack_opt_t *options) { - named_dt_t *dt = *named_dt_head_p; /* Stack pointer */ - named_dt_t *dt_ret = NULL; /* Datatype to return */ - H5O_info2_t oinfo; /* Object info of input dtype */ + named_dt_t *dt = NULL; /* Stack pointer */ + named_dt_t *dt_ret = NULL; /* Datatype to return */ + H5O_info2_t oinfo; /* Object info of input dtype */ int token_cmp; hid_t ret_value = H5I_INVALID_HID; @@ -235,15 +235,13 @@ copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, t H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "H5Oget_info failed"); if (*named_dt_head_p) { - if (H5Otoken_cmp(type_in, &dt->obj_token, &oinfo.token, &token_cmp) < 0) - H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "failed to compare object tokens"); - - /* Stack already exists, search for the datatype */ - while (dt && token_cmp) { - dt = dt->next; - + /* Search the stack for the datatype. */ + for (dt = *named_dt_head_p; dt != NULL; dt = dt->next) { if (H5Otoken_cmp(type_in, &dt->obj_token, &oinfo.token, &token_cmp) < 0) H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "failed to compare object tokens"); + + if (token_cmp == 0) + break; // found it! } dt_ret = dt; |