]> granicus.if.org Git - nethack/commitdiff
Fix possibly uninitialized error
authorPasi Kallinen <paxed@alt.org>
Sat, 22 Jan 2022 19:53:15 +0000 (21:53 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 22 Jan 2022 19:53:15 +0000 (21:53 +0200)
win/curses/cursdial.c

index 86f2a1356c3454555e33334377e67fe9842018cf..993f083b4cbb00773d069fed0578b4df5cae280f 100644 (file)
@@ -373,7 +373,7 @@ curses_ext_cmd(void)
     int ret = -1;
     char cur_choice[BUFSZ];
     int matches = 0;
-    int *ecmatches;
+    int *ecmatches = NULL;
     WINDOW *extwin = NULL, *extwin2 = NULL;
 
     if (iflags.extmenu) {
@@ -421,14 +421,16 @@ curses_ext_cmd(void)
         wclrtoeol(extwin);
 
         /* if we have an autocomplete command, AND it matches uniquely */
-        if (matches == 1) {
+        if (matches == 1 && ecmatches) {
             struct ext_func_tab *ec = extcmds_getentry(ecmatches[0]);
 
-            curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, ON);
-            wmove(extwin, starty, (int) strlen(cur_choice) + startx + 2);
-            wprintw(extwin, "%s",
-                    ec->ef_txt + (int) strlen(cur_choice));
-            curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, OFF);
+            if (ec) {
+                curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, ON);
+                wmove(extwin, starty, (int) strlen(cur_choice) + startx + 2);
+                wprintw(extwin, "%s",
+                        ec->ef_txt + (int) strlen(cur_choice));
+                curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, OFF);
+            }
         }
 
         curs_set(1);
@@ -447,7 +449,7 @@ curses_ext_cmd(void)
             (void) mungspaces(cur_choice);
             if (ret == -1) {
                 matches = extcmds_match(cur_choice, ECM_IGNOREAC|ECM_EXACTMATCH, &ecmatches);
-                if (matches == 1)
+                if (matches == 1 && ecmatches)
                     ret = ecmatches[0];
             }
             break;
@@ -481,7 +483,7 @@ curses_ext_cmd(void)
             ret = -1;
         }
         matches = extcmds_match(cur_choice, ECM_NOFLAGS, &ecmatches);
-        if (matches == 1)
+        if (matches == 1 && ecmatches)
             ret = ecmatches[0];
     }