mirror of
https://github.com/libretro/scummvm.git
synced 2024-11-27 03:10:37 +00:00
AGS: Parser fixes from upstream
Compilation of three bug fixes to text parser I recently made in the AGS project, around alternatives syntax: 1. Stop parsing when reaching end during alternatives skipping (causing an out-of-bounds memory read) 2. Correctly skip over multi-word alternatives (incorrect parsing of alternative lists) 3. Use dedicated function to identify word boundaries (affecting dash and apostrophe containing alternatives) Upstream commits (release-3.6.1 branch): 1. 17f8ea2f0efadec7b3696d4ba51733f1cddc0772 (check for end of input not to go beyond) 2. e98315393a34629b8935fdee7bd725a8299f941c (fix multi-word alternative skipping) 3. 9b0ccbd04e36e757392b1fc744919c785310c57b (consistently check for word boundaries)
This commit is contained in:
parent
fc7adede0c
commit
f9f1a3cbab
@ -242,8 +242,13 @@ int parse_sentence(const char *src_text, int *numwords, short *wordarray, short
|
||||
const char *textStart = ++text; // begin with next char
|
||||
|
||||
// find where the next word ends
|
||||
while ((text[0] == ',') || (Common::isAlnum((unsigned char)text[0]) != 0))
|
||||
text++;
|
||||
while ((text[0] == ',') || is_valid_word_char(text[0])) {
|
||||
// shift beginning of potential multi-word each time we see a comma
|
||||
if (text[0] == ',')
|
||||
textStart = ++text;
|
||||
else
|
||||
text++;
|
||||
}
|
||||
|
||||
continueSearching = 0;
|
||||
|
||||
@ -251,8 +256,11 @@ int parse_sentence(const char *src_text, int *numwords, short *wordarray, short
|
||||
Common::strcpy_s(thisword, textStart);
|
||||
thisword[text - textStart] = 0;
|
||||
// forward past any multi-word alternatives
|
||||
if (FindMatchingMultiWordWord(thisword, &text) >= 0)
|
||||
if (FindMatchingMultiWordWord(thisword, &text) >= 0) {
|
||||
if (text[0] == 0)
|
||||
break;
|
||||
continueSearching = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user