From: Ian Jackson Date: Sun, 5 May 2024 19:12:14 +0000 (+0100) Subject: regress: Handle negative usec deltas X-Git-Tag: adns-1.6.1~8 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3b7d6c90d1a5d6b3bf6762acd1646ca7e65cc89e;p=adns.git regress: Handle negative usec deltas Fixes Debian #1065725 Fixes Ubuntu #2057735 Reported-by: Sebastian Ramacher --- diff --git a/regress/hplayback.c.m4 b/regress/hplayback.c.m4 index dd98f0e..7d0660e 100644 --- a/regress/hplayback.c.m4 +++ b/regress/hplayback.c.m4 @@ -170,19 +170,25 @@ static int Perrno(const char *stuff) { static void P_updatetime(void) { int chars; - unsigned long sec, usec; + unsigned long sec; + long usec; if (!adns__vbuf_ensure(&vb2,1000)) Tnomem(); fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput(); chars= -1; - sscanf(vb2.buf," +%lu.%lu%n",&sec,&usec,&chars); + sscanf(vb2.buf," +%lu.%ld%n",&sec,&usec,&chars); if (chars==-1) Psyntax("update time invalid"); currenttime.tv_sec+= sec; - currenttime.tv_usec+= usec; - if (currenttime.tv_usec > 1000000) { + usec = (long)currenttime.tv_usec + usec; + while (usec < 0) { + currenttime.tv_sec--; + usec += 1000000; + } + while (usec > 1000000) { currenttime.tv_sec++; - currenttime.tv_usec -= 1000000; + usec -= 1000000; } + currenttime.tv_usec = usec; if (vb2.buf[chars] != hm_squote\nhm_squote) Psyntax("not newline after update time"); }