]> granicus.if.org Git - nethack/commitdiff
Qt character selection buglet
authorPatR <rankin@nethack.org>
Mon, 16 Nov 2020 02:19:53 +0000 (18:19 -0800)
committerPatR <rankin@nethack.org>
Mon, 16 Nov 2020 02:19:53 +0000 (18:19 -0800)
Testing for generic character name wasn't robust enough.  Looking
for whether "game" is a generic name would work when compared
with the list "game games" but falsely report 'no' for the list
"games game".  The first matching substring isn't followed by a
space and the routine wasn't checking for other matches in the
rest of the list.  Check again with a subset list starting after
the next space beyond the false hit; repeat as needed.

win/Qt/qt_plsel.cpp

index 85e20ecf64b572b2c8b3e009e0d29f3fb0970b44..bbc3132fa92a9fa911faec5fcbdb7b448722e575 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 static bool generic_plname()
 {
     if (*g.plname) {
-        const char *sptr;
+        const char *sptr, *p;
         const char *genericusers = sysopt.genericusers;
         int ln = (int) strlen(g.plname);
 
@@ -48,12 +48,18 @@ static bool generic_plname()
         else if (!strcmp(genericusers, "*")) /* "*" => always ask for name */
             return true;
 
-        if ((sptr = strstri(genericusers, g.plname)) != 0
+        while ((sptr = strstri(genericusers, g.plname)) != NULL) {
             /* check for full word: start of list or following a space */
-            && (sptr == genericusers || sptr[-1] == ' ')
-            /* and also preceding a space or at end of list */
-            && (sptr[ln] == ' ' || sptr[ln] == '\0'))
-            return true;
+            if ((sptr == genericusers || sptr[-1] == ' ')
+                /* and also preceding a space or at end of list */
+                && (sptr[ln] == ' ' || sptr[ln] == '\0'))
+                return true;
+            /* doesn't match full word, but maybe we got a false hit when
+               looking for "play" in list "player play" so keep going */
+            if ((p = strchr(sptr + 1, ' ')) == NULL)
+                break;
+            genericusers = p + 1;
+        }
     }
     return false;
 }