top: fix potential SEGV when no tasks were displayable

This patch fixes a nearly decade old bug discovered by
Frederik Deweerdt. His merge request shown below would
be an adequate solution except for iterative overhead.

This alternate patch will represent substantially less
overhead for an admittedly extremely rare possibility.

Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/114

And-thanks-to: Frederik Deweerdt <fdeweerdt@fastly.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2020-09-09 00:00:00 -05:00
committed by Craig Small
parent 08d53ae3e6
commit d3203d99dd
2 changed files with 3 additions and 0 deletions

View File

@ -6045,6 +6045,8 @@ static int window_show (WIN_t *q, int wmax) {
// Display Column Headings -- and distract 'em while we sort (maybe)
PUFF("\n%s%s%s", q->capclr_hdr, q->columnhdr, Caps_endline);
// and just in case 'Monpids' is active but matched no processes ...
if (!PIDSmaxt) return 1; // 1 for the column header
if (CHKw(q, Show_FOREST))
forest_begin(q);