URL:
  <https://savannah.gnu.org/bugs/?68307>

                 Summary: The time command produces invalid output in edge
case
                   Group: The GNU Bourne-Again SHell
               Submitter: kcjohnson620
               Submitted: Wed 06 May 2026 01:54:54 AM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Unlocked


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Wed 06 May 2026 01:54:54 AM UTC By: nilpotence <kcjohnson620>
When the 'time' command rounds up, it sometimes produce invalid output. Here
is an example:

$ TIMEFORMAT=%1R
$ time sleep 0.85; time sleep 0.95; time sleep 1.05
0.9
0.:
1.1

The problem is in execute_cmd.c, lines 1307-8 (bash 5.3):

if (rest >= maxval/2)
    frac++;

If 'frac' is 1 unit short of representing a full second then incrementing it
should cause a 1 to carry over into the whole seconds and reset 'frac' to
zero. Since this doesn't happen, the first digit computed on line 1316 ends up
being computed as *10 + '0'*, which resolves to *':'*, effectively overflowing
the list of ASCII digits.

Unfortunately, by the time 'frac' is incremented, it is already too late to
increment 'sec', since it is rendered earlier. Some reordering will be
required to fix this one.

The problem manifests with other values of $TIMEFORMAT, too. I found this with
$TIMEFORMAT undefined, and I was parsing the output from numerous runs. I
found that roughly 1/1000 failed parsing.







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68307>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to