diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2022-02-10 23:23:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 23:23:26 (GMT) |
commit | 0f847f30bc9e5ac8c272fc745aa7c69499455034 (patch) | |
tree | 99e24b51195340dfebba9c1aac363e4db94fafc0 | |
parent | 01092658a3095c31d7dc1ed1beebbd965095c244 (diff) | |
download | hdf5-0f847f30bc9e5ac8c272fc745aa7c69499455034.zip hdf5-0f847f30bc9e5ac8c272fc745aa7c69499455034.tar.gz hdf5-0f847f30bc9e5ac8c272fc745aa7c69499455034.tar.bz2 |
Fix issue with H5_now_usec() with 32 bit systems (#1416)
* Implement H5ESget_requests() to retrieve request pointers and
corresponding connector IDs from an event set. Add tests for this
function.
* Add "order" parameter to H5ESget_requests, to allow the user to specify
the order in which requests are returned.
* Fix bugs with H5ESinsert_request()
* Change H5ESget_requests() API to have separate input and output
parameters for the allocated array length(s) (in) and the number of events in
the event set (out).
* Fix issue with H5_now_usec() with 32 bit systems. Also improve event
set test.
* Committing clang-format changes
* Add comments to H5_now_usec() explaining rationale for uint64_t casts.
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
-rw-r--r-- | src/H5timer.c | 15 | ||||
-rw-r--r-- | test/event_set.c | 30 |
2 files changed, 39 insertions, 6 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); diff --git a/test/event_set.c b/test/event_set.c index 22df510..c2a17b1 100644 --- a/test/event_set.c +++ b/test/event_set.c @@ -344,25 +344,49 @@ test_es_get_requests(void) TEST_ERROR /* Get only connector IDs */ - count = 3; + count = 3; + connector_ids[0] = H5I_INVALID_HID; + connector_ids[1] = H5I_INVALID_HID; if (H5ESget_requests(es_id, H5_ITER_NATIVE, connector_ids, NULL, 2, &count) < 0) TEST_ERROR if (count != 0) TEST_ERROR + if (connector_ids[0] != H5I_INVALID_HID) + TEST_ERROR + if (connector_ids[1] != H5I_INVALID_HID) + TEST_ERROR /* Get only requests */ - count = 3; + count = 3; + requests[0] = NULL; + requests[1] = NULL; if (H5ESget_requests(es_id, H5_ITER_NATIVE, NULL, requests, 2, &count) < 0) TEST_ERROR if (count != 0) TEST_ERROR + if (requests[0] != NULL) + TEST_ERROR + if (requests[1] != NULL) + TEST_ERROR /* Get both */ - count = 3; + count = 3; + connector_ids[0] = H5I_INVALID_HID; + connector_ids[1] = H5I_INVALID_HID; + requests[0] = NULL; + requests[1] = NULL; if (H5ESget_requests(es_id, H5_ITER_NATIVE, connector_ids, requests, 2, &count) < 0) TEST_ERROR if (count != 0) TEST_ERROR + if (connector_ids[0] != H5I_INVALID_HID) + TEST_ERROR + if (connector_ids[1] != H5I_INVALID_HID) + TEST_ERROR + if (requests[0] != NULL) + TEST_ERROR + if (requests[1] != NULL) + TEST_ERROR /* Insert event into event set */ if (H5ESinsert_request(es_id, connector_ids_g[0], &req_targets[0]) < 0) |