From: PatR Date: Mon, 16 Nov 2020 02:19:53 +0000 (-0800) Subject: Qt character selection buglet X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=126d1f6bb66aaa659262a962b6898b7486a11ab8;p=nethack Qt character selection buglet 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. --- diff --git a/win/Qt/qt_plsel.cpp b/win/Qt/qt_plsel.cpp index 85e20ecf6..bbc3132fa 100644 --- a/win/Qt/qt_plsel.cpp +++ b/win/Qt/qt_plsel.cpp @@ -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; }