summaryrefslogtreecommitdiffstats
path: root/src/H5Cimage.c
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2022-04-30 03:29:20 (GMT)
committerGitHub <noreply@github.com>2022-04-30 03:29:20 (GMT)
commitc4d70e3571262df0fcf381f5804b671dc9f86bc1 (patch)
treed5942228d0e2b320b23fdae7c5de278063d77955 /src/H5Cimage.c
parentffd311cf36814c2742234b8a02f47078cb7c8158 (diff)
downloadhdf5-c4d70e3571262df0fcf381f5804b671dc9f86bc1.zip
hdf5-c4d70e3571262df0fcf381f5804b671dc9f86bc1.tar.gz
hdf5-c4d70e3571262df0fcf381f5804b671dc9f86bc1.tar.bz2
Be a bit safer with signed arithmetic, thus quieting some signed-overflow warnings from GCC (#1706)
* Avoid a signed overflow: check the range of `entry_ptr->age` before increasing it instead of increasing it and then checking the range. This quiets a GCC warning. * Avoid the potential for signed overflow by rewriting expressions `MAX(0, fwidth - n)` as `MAX(n, fwidth) - n` for various `n`. This change quiets some GCC warnings. * Change some local variables that cannot take sensible negative values from signed to unsigned. This quiets GCC warnings about potential signed overflow. * In a handful of instances, check the range of a signed integer before increasing/decreasing it, just in case the increase/decrease overflows. This quiets a handful of GCC signed-overflow warnings. * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/H5Cimage.c')
-rw-r--r--src/H5Cimage.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/H5Cimage.c b/src/H5Cimage.c
index ddf5f94..899d6d7 100644
--- a/src/H5Cimage.c
+++ b/src/H5Cimage.c
@@ -2690,10 +2690,11 @@ H5C__prep_for_file_close__setup_image_entries_array(H5C_t *cache_ptr)
*/
if (entry_ptr->type->id == H5AC_PREFETCHED_ENTRY_ID) {
image_entries[u].type_id = entry_ptr->prefetch_type_id;
- image_entries[u].age = entry_ptr->age + 1;
- if (image_entries[u].age > H5AC__CACHE_IMAGE__ENTRY_AGEOUT__MAX)
+ if (entry_ptr->age >= H5AC__CACHE_IMAGE__ENTRY_AGEOUT__MAX)
image_entries[u].age = H5AC__CACHE_IMAGE__ENTRY_AGEOUT__MAX;
+ else
+ image_entries[u].age = entry_ptr->age + 1;
} /* end if */
else {
image_entries[u].type_id = entry_ptr->type->id;