]> granicus.if.org Git - procps-ng/commitdiff
top: refactor 'mkVIZ' support to avoid future problems
authorJim Warner <james.warner@comcast.net>
Wed, 16 Jun 2021 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Thu, 17 Jun 2021 06:46:33 +0000 (16:46 +1000)
In the patch referenced below, 2 potential abends were
fixed both of which involved 'alternate display mode'.

The root cause of those abends was a negative value in
the 'begnext' field for other than the current window.

And while that potential is fixed for now the existing
code almost invites such problems again in the future.

So, this patch will remove any temptation to name some
other window in the 'mkVIZrow1' macro. And, since that
macro is not the only source of 'begnext' changes, the
'mkVizrowX' is being added to identify such occasions.

[ and for symmetry i've added a 'mkVIZyes' macro and ]
[ ameliorated an otherwise surreptitious assignment! ]

Reference(s):
commit 84e85611c36d31a478e1b62e5668671d9389265d

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

index dd6e3d58a3676aa9014cb1a75d8a7121ab0be916..4d9860d511dd546e7cd93d2d1df59c50e0fdb366 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -4719,7 +4719,7 @@ static void wins_stage_2 (void) {
 
    // with preserved 'other filters' & command line 'user filters',
    // we must ensure that we always have a visible task on row one.
-   mkVIZrow1(Curwin);
+   mkVIZrow1
 
    // lastly, initialize a signal set used to throttle one troublesome signal
    sigemptyset(&Sigwinch_set);
@@ -5147,7 +5147,7 @@ static void keys_global (int ch) {
       case '?':
       case 'h':
          help_view();
-         mkVIZrow1(Curwin);
+         mkVIZrow1
          break;
       case 'B':
          TOGw(w, View_NOBOLD);
@@ -5175,7 +5175,7 @@ static void keys_global (int ch) {
          break;
       case 'g':
          win_select(0);
-         mkVIZrow1(Curwin);
+         mkVIZrow1
          break;
       case 'H':
          Thread_mode = !Thread_mode;
@@ -5255,7 +5255,7 @@ static void keys_global (int ch) {
          break;
       case 'Z':
          wins_colors();
-         mkVIZrow1(Curwin);
+         mkVIZrow1
          break;
       case '0':
          Rc.zero_suppress = !Rc.zero_suppress;
@@ -5459,7 +5459,7 @@ static void keys_task (int ch) {
       case kbd_CtrlO:
          if (VIZCHKw(w)) {
             other_filters(ch);
-            mkVIZrow1(w);
+            mkVIZrow1
          }
          break;
       case 'U':
@@ -5469,7 +5469,7 @@ static void keys_task (int ch) {
             if (*str != kbd_ESC
             && (errmsg = user_certify(w, str, ch)))
                 show_msg(errmsg);
-            mkVIZrow1(w);
+            mkVIZrow1
          }
          break;
       case 'V':
@@ -5577,7 +5577,7 @@ static void keys_window (int ch) {
       case 'w':
          if (ALTCHKw) {
             win_select(ch);
-            mkVIZrow1(Curwin);
+            mkVIZrow1
          }
          break;
       case 'G':
@@ -5588,10 +5588,10 @@ static void keys_window (int ch) {
          }
          break;
       case kbd_UP:
-         if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS)) w->begnext = -1;
+         if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS)) mkVIZrowX(-1)
          break;
       case kbd_DOWN:
-         if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS)) w->begnext = +1;
+         if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS)) mkVIZrowX(+1)
          break;
 #ifdef USE_X_COLHDR // ------------------------------------
       case kbd_LEFT:
@@ -5661,30 +5661,30 @@ static void keys_window (int ch) {
       case kbd_PGUP:
          if (VIZCHKw(w)) {
             if (CHKw(w, Show_IDLEPS) && 0 < w->begtask) {
-               w->begnext = -(w->winlines - (Rc.mode_altscr ? 1 : 2));
+               mkVIZrowX(-(w->winlines - (Rc.mode_altscr ? 1 : 2)))
             }
          }
          break;
       case kbd_PGDN:
          if (VIZCHKw(w)) {
             if (CHKw(w, Show_IDLEPS) && w->begtask < Frame_maxtask - 1) {
-               w->begnext = +(w->winlines - (Rc.mode_altscr ? 1 : 2));
+               mkVIZrowX(+(w->winlines - (Rc.mode_altscr ? 1 : 2)))
             }
          }
          break;
       case kbd_HOME:
 #ifndef SCROLLVAR_NO
          if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS)) w->begtask = w->begpflg = w->varcolbeg = 0;
-         mkVIZrow1(w);
+         mkVIZrow1
 #else
          if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS)) w->begtask = w->begpflg = 0;
-         mkVIZrow1(w);
+         mkVIZrow1
 #endif
          break;
       case kbd_END:
          if (VIZCHKw(w)) {
             if (CHKw(w, Show_IDLEPS)) {
-               w->begnext = (Frame_maxtask - w->winlines) + 1;
+               mkVIZrowX((Frame_maxtask - w->winlines) + 1)
                w->begpflg = w->endpflg;
 #ifndef SCROLLVAR_NO
                w->varcolbeg = 0;
@@ -6438,7 +6438,8 @@ static const char *task_show (const WIN_t *q, const int idx) {
          *   1) exclusively for the 'current' window
          *   2) immediately after interacting with the user
          *   3) who struck: up, down, pgup, pgdn, home, end, 'o/O' or 'u/U'
-         *   4) or upon the user switching from one window to another window */
+         *   4) or upon the user switching from one window to another window
+         * ( note: it's entirely possible there are NO visible tasks to show ) */
 static void window_hlp (void) {
    WIN_t *w = Curwin;             // avoid gcc bloat with a local copy
    int i, reversed;
@@ -6472,8 +6473,10 @@ fwd_redux:
       && (*task_show(w, i)))
          break;
    }
+   w->begtask = i;
+
    // reached the top, but maybe this guy ain't visible
-   if (!(w->begtask = i) && !reversed) {
+   if (!w->begtask && !reversed) {
       if (!(wins_usrselect(w, 0))
       || (!(*task_show(w, 0)))) {
          reversed = 1;
@@ -6513,7 +6516,7 @@ static int window_show (WIN_t *q, int wmax) {
       qsort(q->ppt, Frame_maxtask, sizeof(proc_t *), Fieldstab[q->rc.sortindx].sort);
    }
 
-   if (q->begnext) window_hlp();
+   if (mkVIZyes) window_hlp();
    else OFFw(q, NOPRINT_xxx);
 
    i = q->begtask;
index 1a378531079f19725ab69358e8b3b359a4d35db6..62c5ed9b540c0a79267431fc75534a59d38efbbf 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -476,7 +476,9 @@ typedef struct WIN_t {
 
         // Support for a proper (visible) row #1 whenever Curwin changes
         // ( or a key which might affect vertical scrolling was struck )
-#define mkVIZrow1(q) { q->begtask -= 1; q->begnext = +1; }
+#define mkVIZyes       Curwin->begnext != 0
+#define mkVIZrow1    { Curwin->begnext = +1; Curwin->begtask -= 1; }
+#define mkVIZrowX(n) { Curwin->begnext = (n); }
 
         /* Special Section: end ------------------------------------------ */
         /* /////////////////////////////////////////////////////////////// */