diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2022-04-08 13:22:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-08 13:22:07 (GMT) |
commit | 236297c00d630b391b2ee3b98e67b0b83d642a12 (patch) | |
tree | 4c047585c6c8878d3d592dc398536ccff27ee5ee /src/H5timer.c | |
parent | 02d0208187af16137d01a3261961ab8fabd65d28 (diff) | |
download | hdf5-236297c00d630b391b2ee3b98e67b0b83d642a12.zip hdf5-236297c00d630b391b2ee3b98e67b0b83d642a12.tar.gz hdf5-236297c00d630b391b2ee3b98e67b0b83d642a12.tar.bz2 |
1.12: Last round of normalizations for 1.12.2 (#1621)
Diffstat (limited to 'src/H5timer.c')
-rw-r--r-- | src/H5timer.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/H5timer.c b/src/H5timer.c index b2cc5f0..b5dba97 100644 --- a/src/H5timer.c +++ b/src/H5timer.c @@ -193,17 +193,26 @@ H5_now_usec(void) struct timespec ts; HDclock_gettime(CLOCK_MONOTONIC, &ts); - now = (uint64_t)(ts.tv_sec * (1000 * 1000)) + (uint64_t)(ts.tv_nsec / 1000); + + /* Cast all values in this expression to uint64_t to ensure that all intermediate + * calculations are done in 64 bit, to prevent overflow */ + now = ((uint64_t)ts.tv_sec * ((uint64_t)1000 * (uint64_t)1000)) + + ((uint64_t)ts.tv_nsec / (uint64_t)1000); } #elif defined(H5_HAVE_GETTIMEOFDAY) { struct timeval now_tv; HDgettimeofday(&now_tv, NULL); - now = (uint64_t)(now_tv.tv_sec * (1000 * 1000)) + (uint64_t)now_tv.tv_usec; + + /* Cast all values in this expression to uint64_t to ensure that all intermediate + * calculations are done in 64 bit, to prevent overflow */ + now = ((uint64_t)now_tv.tv_sec * ((uint64_t)1000 * (uint64_t)1000)) + (uint64_t)now_tv.tv_usec; } #else /* H5_HAVE_GETTIMEOFDAY */ - now = (uint64_t)(HDtime(NULL) * (1000 * 1000)); + /* Cast all values in this expression to uint64_t to ensure that all intermediate calculations + * are done in 64 bit, to prevent overflow */ + now = ((uint64_t)HDtime(NULL) * ((uint64_t)1000 * (uint64_t)1000)); #endif /* H5_HAVE_GETTIMEOFDAY */ return (now); |