From ff7373f46fd0a658b9592374f0cd6554adc47720 Mon Sep 17 00:00:00 2001 From: Ankita-gupta Date: Thu, 30 Aug 2012 13:33:19 +0200 Subject: [PATCH] Fixed bug in Token::Match (#3720) --- lib/token.cpp | 4 ++-- test/testtoken.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index db386e4d2..428547550 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -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': diff --git a/test/testtoken.cpp b/test/testtoken.cpp index fd96e468d..1156b46b1 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -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() {