Skip to content

Commit

Permalink
Refactor zic overflow checking
Browse files Browse the repository at this point in the history
* zic.c (oadd, tadd): Negate sense of branch,
to simplify future changes.
(tadd): Simplify.
  • Loading branch information
eggert committed Nov 20, 2022
1 parent 8e303be commit ad10807
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions zic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/*
Expand Down

0 comments on commit ad10807

Please sign in to comment.