Skip to content

Commit 57ff467

Browse files
committed
Fix very silly bug in times builtin (re: 65d363f)
Well, that's what I get for backporting code without properly checking it over. There was an elementary math error in how the times builtin calculated seconds: utime_sec = utime - utime_min; which could cause output such as "1m98.38s" or "3m234.77s". src/cmd/ksh93/bltins/misc.c: b_times(): - Use fmod(), i.e. floating point modulus, to calculate seconds.
1 parent d8fe061 commit 57ff467

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/cmd/ksh93/bltins/misc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,19 @@ int b_times(int argc, char *argv[], Shbltin_t *context)
498498
/* First line: user and system times used by the shell */
499499
utime = (double)cpu_times.tms_utime / shp->gd->lim.clk_tck;
500500
utime_min = floor(utime / 60);
501-
utime_sec = utime - utime_min;
501+
utime_sec = fmod(utime, 60);
502502
stime = (double)cpu_times.tms_stime / shp->gd->lim.clk_tck;
503503
stime_min = floor(stime / 60);
504-
stime_sec = stime - stime_min;
504+
stime_sec = fmod(stime, 60);
505505
sfprintf(sfstdout, "%dm%.2fs %dm%.2fs\n", (int)utime_min, utime_sec, (int)stime_min, stime_sec);
506506

507507
/* Second line: same for the shell's child processes */
508508
utime = (double)cpu_times.tms_cutime / shp->gd->lim.clk_tck;
509509
utime_min = floor(utime / 60);
510-
utime_sec = utime - utime_min;
510+
utime_sec = fmod(utime, 60);
511511
stime = (double)cpu_times.tms_cstime / shp->gd->lim.clk_tck;
512512
stime_min = floor(stime / 60);
513-
stime_sec = stime - stime_min;
513+
stime_sec = fmod(stime, 60);
514514
sfprintf(sfstdout, "%dm%.2fs %dm%.2fs\n", (int)utime_min, utime_sec, (int)stime_min, stime_sec);
515515

516516
return(0);

0 commit comments

Comments
 (0)