[Pkg-wmaker-commits] [wmhdplop] 02/03: wmhdplop: fix integer overflow

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Feb 17 10:12:24 UTC 2017


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository wmhdplop.

commit 3ce4664a8836b3b6bbd7275d5e315bc4ca2ac0b2
Author: Mikael Magnusson <mikachu at gmail.com>
Date:   Thu Feb 16 15:16:42 2017 +0100

    wmhdplop: fix integer overflow
    
    After a while, the procstats fields will overflow the
    signed int field and the hd leds will be permanently on.
    
    Use long instead of int for these counters
    
    Gentoo original bug: https://bugs.gentoo.org/show_bug.cgi?id=325615
---
 devnames.h |  2 +-
 procstat.c | 18 +++++++++---------
 procstat.h |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/devnames.h b/devnames.h
index 0f57d41..15b0f73 100644
--- a/devnames.h
+++ b/devnames.h
@@ -9,7 +9,7 @@ typedef struct DiskList {
   unsigned major, minor;
   int hd_id, part_id; /* part_id = 0 for disks */
   int enable_hddtemp;
-  int nr, nw, touched_r, touched_w;
+  long nr, nw, touched_r, touched_w;
   struct DiskList *next;
 } DiskList;
 
diff --git a/procstat.c b/procstat.c
index e7eed1b..d51b53c 100644
--- a/procstat.c
+++ b/procstat.c
@@ -8,7 +8,7 @@
 static ProcStats ps;
 int use_proc_diskstats;
 
-void pstat_init(struct pstat *pst, int nslice, float update_interval) {
+void pstat_init(struct pstat *pst, long nslice, float update_interval) {
   pst->nslice = nslice;
   ALLOC_VEC(pst->slices, nslice);
   pst->cur_slice = 0;
@@ -17,7 +17,7 @@ void pstat_init(struct pstat *pst, int nslice, float update_interval) {
 }
 
 float pstat_current(struct pstat *pst) {
-  int idx = pst->cur_slice ? pst->cur_slice-1 : pst->nslice-1;
+  long idx = pst->cur_slice ? pst->cur_slice-1 : pst->nslice-1;
   return pst->slices[idx]/pst->update_interval;
 }
 
@@ -100,13 +100,13 @@ void update_stats() {
             if (!Prefs.debug_disk_rd) {
               pstat_add(&ps.disk_read, nr);
             } else {
-              static int cntr = 0; cntr+=(rand()%30) == 0 ? Prefs.debug_disk_rd : 0;
+              static long cntr = 0; cntr+=(rand()%30) == 0 ? Prefs.debug_disk_rd : 0;
               pstat_add(&ps.disk_read, nr + cntr);
             }
             if (!Prefs.debug_disk_wr) {
               pstat_add(&ps.disk_write, nw);
             } else {
-              static int cntw = 0; cntw+=(rand()%30) == 0 ? Prefs.debug_disk_wr : 0;
+              static long cntw = 0; cntw+=(rand()%30) == 0 ? Prefs.debug_disk_wr : 0;
               pstat_add(&ps.disk_write, nw + cntw);
             }
             readok = 2;
@@ -120,7 +120,7 @@ void update_stats() {
               pstat_add(&ps.swap_in, nr);
               pstat_add(&ps.swap_out, nw);
             } else {
-              static int cnt = 0; cnt+=Prefs.debug_swapio;
+              static long cnt = 0; cnt+=Prefs.debug_swapio;
               pstat_add(&ps.swap_in, nr + cnt);
               pstat_add(&ps.swap_out, nw + cnt);
             }
@@ -143,10 +143,10 @@ void init_stats(float update_interval) {
   char s[512];
   FILE *f;
 
-  pstat_init(&ps.swap_in, (int)(0.5/update_interval)+1, update_interval);
-  pstat_init(&ps.swap_out, (int)(0.5/update_interval)+1, update_interval);
-  pstat_init(&ps.disk_read, (int)(0.5/update_interval)+1, update_interval);
-  pstat_init(&ps.disk_write, (int)(0.5/update_interval)+1, update_interval);
+  pstat_init(&ps.swap_in, (long)(0.5/update_interval)+1, update_interval);
+  pstat_init(&ps.swap_out, (long)(0.5/update_interval)+1, update_interval);
+  pstat_init(&ps.disk_read, (long)(0.5/update_interval)+1, update_interval);
+  pstat_init(&ps.disk_write, (long)(0.5/update_interval)+1, update_interval);
   f = fopen("/proc/swaps","r");
   //if (!f) { perror("/proc/swaps"); exit(1); }
   if (f) {
diff --git a/procstat.h b/procstat.h
index 2107055..abce78f 100644
--- a/procstat.h
+++ b/procstat.h
@@ -4,7 +4,7 @@
 
 struct pstat {
   unsigned long total;
-  int nslice, cur_slice;
+  long nslice, cur_slice;
   unsigned long *slices;
   float update_interval;
 };
@@ -15,7 +15,7 @@ typedef struct {
   struct pstat disk_read, disk_write;
 } ProcStats;
 
-void pstat_init(struct pstat *pst, int nslice, float update_interval);
+void pstat_init(struct pstat *pst, long nslice, float update_interval);
 float pstat_current(struct pstat *pst);
 void pstat_add(struct pstat *pst, unsigned long v);
 void pstat_advance(struct pstat *pst);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmhdplop.git



More information about the Pkg-wmaker-commits mailing list