From 256d7c17e9269f82a8f006dc50308d7934b93ce3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 16 Jun 2022 17:40:18 -0700 Subject: bugfix: hokey long interval calculation. The intent is to have a clock which measures milliseconds and wraps around from 1000000000 (billion) back to zero, fitting into 32 bits. The now - lastttime calculation must be done modulo a billion. The difference could be negative because of the wrap; to ensure we get a positive residue, we add a billion. --- pw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pw.c b/pw.c index 7f98136..44d0faa 100644 --- a/pw.c +++ b/pw.c @@ -1571,7 +1571,9 @@ int main(int argc, char **argv) gettimeofday(&tv, NULL); now = tv.tv_sec % 1000000 * 1000 + tv.tv_usec / 1000; - if (lasttime == -1 || now - lasttime > long_interval) { + if (lasttime == -1 || + (now + 1000000000 - lasttime) % 1000000000 > long_interval) + { if ((pw.stat & stat_dirty) && pw.nlines == pw.maxlines) force = 1; lasttime = now; -- cgit v1.2.3