From: Jim Warner Date: Tue, 17 Jul 2018 05:00:00 +0000 (-0500) Subject: top: fix the collapsed children cpu segmentation fault X-Git-Tag: v3.3.16~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=786bffc25399e2b64d2a5ad2203faf71b9bfaac3;p=procps-ng top: fix the collapsed children cpu segmentation fault 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 --- diff --git a/top/top.c b/top/top.c index 1d664467..49c44e60 100644 --- 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