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 /hl/test | |
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 'hl/test')
-rw-r--r-- | hl/test/test_image.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/hl/test/test_image.c b/hl/test/test_image.c index 0c7d511..dc1be96 100644 --- a/hl/test/test_image.c +++ b/hl/test/test_image.c @@ -650,10 +650,10 @@ test_generate(void) HL_TESTING2("make indexed image from land data"); for (i = 0; i < n_elements; i++) { - if (data[i] < 0) + if (data[i] < 0.0f) image_data[i] = 0; else - image_data[i] = (unsigned char)((255 * (data[i])) / xmax); + image_data[i] = (unsigned char)((255 * data[i]) / xmax); } /* make the image */ @@ -671,10 +671,11 @@ test_generate(void) HL_TESTING2("make indexed image from sea data"); for (i = 0; i < n_elements; i++) { - if (data[i] > 0) + if (data[i] > 0.0f) image_data[i] = 0; - else - image_data[i] = (unsigned char)((255 * (data[i] - xmin)) / xmin); + else { + image_data[i] = (unsigned char)((255.0f * (data[i] - xmin)) / (xmax - xmin)); + } } /* make the image */ |