]> git.puffer.fish Git - matthieu/frr.git/commit
lib: Ensure order of operations is expected with SECONDS
authorDonald Sharp <sharpd@nvidia.com>
Sat, 26 Mar 2022 20:20:53 +0000 (16:20 -0400)
committermergify-bot <noreply@mergify.com>
Sun, 27 Mar 2022 17:47:55 +0000 (17:47 +0000)
commit5363edd7d72199ce42631e2739a1ce6ddf4d1c7a
treeb09661816f69bcf8a35f222b60c802190b4d0833
parent7e0386aaf2b11e27f97f8fc6d378c86b2b506b96
lib: Ensure order of operations is expected with SECONDS

These 3 values:
ONE_DAY_SECOND
ONE_WEEK_SECOND
ONE_YEAR_SECOND

Are defined based upon the number of seconds.  Unfortunately doing math
on these values say something like:

days = t->tv_sec / ONE_DAY_SECOND;

Once you go over about a day causes the order of operations to cause the multiplication
to get messed up:

204 if (!t)
(gdb) n
207 w = d = h = m = ms = 0;
(gdb) set t->tv_sec = ONE_DAY_SECOND + 30
(gdb) n
208 memset(buf, 0, size);
(gdb)
210 us = t->tv_usec;
(gdb)
211 if (us >= 1000) {
(gdb)
212 ms = us / 1000;
(gdb)
213 us %= 1000;
(gdb)
217 if (ms >= 1000) {
(gdb)
222 if (t->tv_sec > ONE_WEEK_SECOND) {
(gdb)
227 if (t->tv_sec > ONE_DAY_SECOND) {
(gdb)
228 d = t->tv_sec / ONE_DAY_SECOND;
(gdb) n
229 t->tv_sec -= d * ONE_DAY_SECOND;
(gdb) n
232 if (t->tv_sec >= HOUR_IN_SECONDS) {
(gdb) p d
$6 = 2073600
(gdb) p t->tv_sec
$7 = -179158953570
(gdb)

Converting to adding paranthesis around around the ONE_DAY_SECOND causes
the order of operations to work as expected.

Fixes: #10880
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit bddfc297419843cf075ae5524b6647735b00e9f9)
lib/monotime.h