Fixed bug in Token::Match (#3720)

This commit is contained in:
Ankita-gupta 2012-08-30 13:33:19 +02:00 committed by PKEuS
parent 0d26a79f2c
commit ff7373f46f
2 changed files with 7 additions and 2 deletions

View File

@ -341,7 +341,7 @@ static int multiComparePercent(const char * * haystack_p,
{
const char *haystack = *haystack_p;
if (haystack[0] == '%' && haystack[1] != '|') {
if (haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ') {
if (haystack[1] == 'o' && // "%op%"
haystack[2] == 'p' &&
haystack[3] == '%') {
@ -564,7 +564,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
// Compare the first character of the string for optimization reasons
// before doing more detailed checks.
if (p[0] == '%') {
if (p[0] == '%' && p[1]!='|') {
bool patternUnderstood = false;
switch (p[1]) {
case 'v':

View File

@ -166,6 +166,11 @@ private:
ASSERT_EQUALS(true, Token::Match(toks3.tokens(), "return %var% xyz|%oror% %var% ;"));
ASSERT_EQUALS(true, Token::Match(toks3.tokens(), "return %var% %oror%|xyz %var% ;"));
givenACodeSampleToTokenize toks4("a % b ;", true);
ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%var% >>|<<|&|%or%|^|% %var% ;"));
ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%var% %|>>|<<|&|%or%|^ %var% ;"));
ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%var% >>|<<|&|%or%|%|^ %var% ;"));
}
void getStrLength() {