From 8159bae9d03cc371ae7544217402e5073a778332 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Mon, 23 Oct 1995 19:05:50 +0000 Subject: [PATCH] Fix a sign extension bug that was unleashed by the previous change. The total process time was sometimes 2^32 usec too large but that wasn't a problem before because the time was bogusly truncated mod 2^32. --- sys/kern/kern_resource.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index db58b913bee1..db00d4312ee4 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 - * $Id: kern_resource.c,v 1.12 1995/05/30 08:05:39 rgrimes Exp $ + * $Id: kern_resource.c,v 1.13 1995/10/21 09:18:45 bde Exp $ */ #include @@ -455,8 +455,9 @@ calcru(p, up, sp, ip) register struct timeval *sp; register struct timeval *ip; { + register quad_t totusec; register u_quad_t u, st, ut, it, tot; - register u_long sec, usec; + register long sec, usec; register int s; struct timeval tv; @@ -487,7 +488,12 @@ calcru(p, up, sp, ip) sec += tv.tv_sec - runtime.tv_sec; usec += tv.tv_usec - runtime.tv_usec; } - u = (u_quad_t) sec * 1000000 + usec; + totusec = (quad_t)sec * 1000000 + usec; + if (totusec < 0) { + printf("calcru: negative time: %qd usec\n", totusec); + totusec = 0; + } + u = totusec; st = (u * st) / tot; sp->tv_sec = st / 1000000; sp->tv_usec = st % 1000000;