[tz] [PATCH 4/5] Refactor zic overflow checking
Paul Eggert
eggert at cs.ucla.edu
Sun Nov 20 05:13:11 UTC 2022
* zic.c (oadd, tadd): Negate sense of branch,
to simplify future changes.
(tadd): Simplify.
---
zic.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/zic.c b/zic.c
index 9f5bd38..45dffea 100644
--- a/zic.c
+++ b/zic.c
@@ -3690,28 +3690,19 @@ time_overflow(void)
static ATTRIBUTE_PURE zic_t
oadd(zic_t t1, zic_t t2)
{
- if (t1 < 0 ? t2 < ZIC_MIN - t1 : ZIC_MAX - t1 < t2)
- time_overflow();
- return t1 + t2;
+ if (t1 < 0 ? ZIC_MIN - t1 <= t2 : t2 <= ZIC_MAX - t1)
+ return t1 + t2;
+ time_overflow();
}
static ATTRIBUTE_PURE zic_t
tadd(zic_t t1, zic_t t2)
{
- if (t1 < 0) {
- if (t2 < min_time - t1) {
- if (t1 != min_time)
- time_overflow();
- return min_time;
- }
- } else {
- if (max_time - t1 < t2) {
- if (t1 != max_time)
- time_overflow();
- return max_time;
- }
- }
- return t1 + t2;
+ if (t1 < 0 ? min_time - t1 <= t2 : t2 <= max_time - t1)
+ return t1 + t2;
+ if (t1 == min_time || t1 == max_time)
+ return t1;
+ time_overflow();
}
/*
--
2.38.1
More information about the tz
mailing list