bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: "Семен Верченко" <semverchenko@factor-ts.ru>
To: bug-gnulib@gnu.org
Subject: [PATCH] Fix getloadavg bug
Date: Mon, 1 Jun 2020 19:49:55 +0300	[thread overview]
Message-ID: <9892dc0d-597f-6bef-b635-c6d2f2359609@factor-ts.ru> (raw)

getloadavg function increases elem counter twice:

  for (elem = 0; elem < nelem; elem++) // Here
    {
      // ...

      loadavg[elem++] = numerator / denominator; // And here
    }

It leads to wrong Load Average in uptime command:
$ cat /proc/loadavg
0.01 0.02 0.00 1/122 992
$ uptime
 18:36:59 up   6:20,  0 users,  load average: 0,01, 0,00, 0,02

This patch fixes this bug
---
 lib/getloadavg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index 61307d377..aeb7070cc 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -550,7 +550,7 @@ getloadavg (double loadavg[], int nelem)
         for (ptr++; '0' <= *ptr && *ptr <= '9'; ptr++)
           numerator = 10 * numerator + (*ptr - '0'), denominator *= 10;
 -      loadavg[elem++] = numerator / denominator;
+      loadavg[elem] = numerator / denominator;
     }
    return elem;
-- 
2.26.2



             reply	other threads:[~2020-06-01 18:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-01 16:49 Семен Верченко [this message]
2020-06-02  0:58 ` [PATCH] Fix getloadavg bug Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9892dc0d-597f-6bef-b635-c6d2f2359609@factor-ts.ru \
    --to=semverchenko@factor-ts.ru \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).