summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-10-29 21:04:47 +0100
committerMichal Schmidt <mschmidt@redhat.com>2012-10-29 22:57:24 +0100
commitfd09c93de9337c3df566180d04368353bb3662e7 (patch)
treea6bc402f8e7fd2947f1557dede8908ab90e017df /src/shared/util.c
parentf36d7992ef9588e24feaae5bb3d103ca63af71bd (diff)
util: improve overflow checks
commit 49371bb fixed the observed division by zero, but missed another occurrence of the same bug. It was also not the optimal fix. We can simply make the divisor a constant by swapping it with the compared value.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 9a45e6058e..8ec83e49a8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -148,8 +148,7 @@ usec_t timespec_load(const struct timespec *ts) {
ts->tv_nsec == (long) -1)
return (usec_t) -1;
- if (ts->tv_sec > 0 &&
- USEC_PER_SEC > ((UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / (usec_t) ts->tv_sec))
+ if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
return (usec_t) -1;
return
@@ -179,7 +178,7 @@ usec_t timeval_load(const struct timeval *tv) {
tv->tv_usec == (suseconds_t) -1)
return (usec_t) -1;
- if (USEC_PER_SEC > (UINT64_MAX - tv->tv_usec) / (usec_t) tv->tv_sec)
+ if ((usec_t) tv->tv_sec > (UINT64_MAX - tv->tv_usec) / USEC_PER_SEC)
return (usec_t) -1;
return