]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
getloadavg: fix double-increment bug
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 2 Jun 2020 00:57:27 +0000 (17:57 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 2 Jun 2020 00:57:40 +0000 (17:57 -0700)
* lib/getloadavg.c (getloadavg): Fix double-increment typo on
Linux without glibc, Android, Cygwin.  This fixes a bug I
introduced in 2011-02-08T20:23:29Z!eggert@cs.ucla.edu.
Problem and fix reported by Semen Verchenko in:
https://lists.gnu.org/r/bug-gnulib/2020-06/msg00007.html

ChangeLog
lib/getloadavg.c

index 5a07e5ae71bfa22575e4d9e9b0756ba6dfdd333a..7e3e708521a4ed9e6854c416819b52be3d17ac42 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-06-01  Paul Eggert  <eggert@cs.ucla.edu>
 
+       getloadavg: fix double-increment bug
+       * lib/getloadavg.c (getloadavg): Fix double-increment typo on
+       Linux without glibc, Android, Cygwin.  This fixes a bug I
+       introduced in 2011-02-08T20:23:29Z!eggert@cs.ucla.edu.
+       Problem and fix reported by Semen Verchenko in:
+       https://lists.gnu.org/r/bug-gnulib/2020-06/msg00007.html
+
        tempname: use getrandom, not getentropy
        This removes a dependency, as getentropy depends on getrandom.
        * lib/tempname.c: Include sys/random.h instead of unistd.h.
index 61307d3772a391776d7be58fb98a2657d69408c3..aeb7070cc7953b62ba8f90456e2ec0e5c2e4bdee 100644 (file)
@@ -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;