summaryrefslogtreecommitdiff
path: root/src/basic/time-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-09 19:55:04 +0100
committerLennart Poettering <lennart@poettering.net>2016-02-10 13:26:56 +0100
commit04a1d84cefe4dbb5bfee86190489c3c07a8c238c (patch)
tree702412b2fe4c9981386f7c8e9f1d2519e02faaf5 /src/basic/time-util.h
parent6bf0f408e4833152197fb38fb10a9989c89f3a59 (diff)
util-lib: make sure usec_sub() doesn't degrade USEC_INFINITY
As suggested in: https://github.com/systemd/systemd/pull/2542#issuecomment-181877820
Diffstat (limited to 'src/basic/time-util.h')
-rw-r--r--src/basic/time-util.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 87440faeee..080c1110f5 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -143,11 +143,13 @@ static inline usec_t usec_add(usec_t a, usec_t b) {
static inline usec_t usec_sub(usec_t timestamp, int64_t delta) {
if (delta < 0)
- timestamp = usec_add(timestamp, (usec_t) (-delta));
- else if (timestamp > (usec_t) delta)
- timestamp -= delta;
- else
- timestamp = 0;
+ return usec_add(timestamp, (usec_t) (-delta));
- return timestamp;
+ if (timestamp == USEC_INFINITY) /* Make sure infinity doesn't degrade */
+ return USEC_INFINITY;
+
+ if (timestamp < (usec_t) delta)
+ return 0;
+
+ return timestamp - delta;
}