]> granicus.if.org Git - procps-ng/commitdiff
top: fix the collapsed children cpu segmentation fault
authorJim Warner <james.warner@comcast.net>
Tue, 17 Jul 2018 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Wed, 18 Jul 2018 10:17:22 +0000 (20:17 +1000)
While that 'Hide_cpu' value will always be zero unless
there are collapsed children, the damn array will only
be present when a window's in 'Show_FOREST' view mode.

Reference(s):
https://www.freelists.org/post/procps/important-improvements-to-top,8

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 1d664467e2b1ea5279e70be78a9b756382a21cb6..49c44e60e927be930937c771133baa40e32f19b7 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -4692,7 +4692,7 @@ static int      Tree_idx;                   // frame_make resets to zero
 static int *Hide_pid;                       // collapsible process array
 static int  Hide_tot;                       // total used in above array
 #ifndef TREE_VCPUOFF
-static int *Hide_cpu;                       // accum tics from collapsed
+static unsigned *Hide_cpu;                  // accum tics from collapsed
 #endif
 
         /*
@@ -4749,7 +4749,7 @@ static void forest_create (WIN_t *q) {
          Tree_ppt = alloc_r(Tree_ppt, sizeof(proc_t*) * hwmsav);
          Hide_pid = alloc_r(Hide_pid, sizeof(int) * hwmsav);
 #ifndef TREE_VCPUOFF
-         Hide_cpu = alloc_r(Hide_cpu, sizeof(int) * hwmsav);
+         Hide_cpu = alloc_r(Hide_cpu, sizeof(unsigned) * hwmsav);
 #endif
       }
 
@@ -4761,7 +4761,7 @@ static void forest_create (WIN_t *q) {
             forest_adds(i, 0);              // add a parent and its children
       }
 #ifndef TREE_VCPUOFF
-      memset(Hide_cpu, 0, sizeof(int) * Frame_maxtask);
+      memset(Hide_cpu, 0, sizeof(unsigned) * Frame_maxtask);
 #endif
       /* we're borrowing some pad bytes in the proc_t,
          pad_2: 'x' means a collapsed thread, 'z' means an unseen child
@@ -6002,7 +6002,7 @@ static const char *task_show (const WIN_t *q, const int idx) {
          {  float u = (float)p->pcpu;
 #ifndef TREE_VCPUOFF
             // Hide_cpu entry is always zero, unless we're a collapsed parent
-            u += Hide_cpu[idx];
+            if (CHKw(q, Show_FOREST)) u += Hide_cpu[idx];
             u *= Frame_etscale;
             if (p->pad_2 != 'x' && u > 100.0 * p->nlwp) u = 100.0 * p->nlwp;
 #else