[2/3,gdb/tui] Fix buglet in set_border_kind_item

Message ID 20230508141036.22723-3-tdevries@suse.de
State Superseded
Headers
Series Add tui border-kind active-ascii |

Commit Message

Tom de Vries May 8, 2023, 2:10 p.m. UTC
  While factoring out set_border_kind_item I noticed a buglet:
...
  struct tui_translate *entry = translate (key, dict);

  if (*lval != (chtype) entry->value)
    {
      *lval = (entry->value < 0) ? acs : entry->value;
...

When assigning the new value to *lval, an entry->value of -1 is taken into
account, but not when comparing to the current value of *lval.

Fix this by introducing:
...
  int val = (entry->value < 0) ? acs : entry->value;
...
and using this in both comparison and assignment.

Tested on x86_64-linux.
---
 gdb/tui/tui-win.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index cf4cb920524..fedcac4b560 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -300,10 +300,11 @@  set_border_kind_item (chtype *lval, const char *key,
 		      struct tui_translate *dict, int acs, bool *lval_changed)
 {
   struct tui_translate *entry = translate (key, dict);
+  int val = (entry->value < 0) ? acs : entry->value;
 
-  if (*lval != (chtype) entry->value)
+  if (*lval != (chtype) val)
     {
-      *lval = (entry->value < 0) ? acs : entry->value;
+      *lval = val;
       *lval_changed = true;
     }
 }