Fixed #8211 (Crash on incomplete code in isVariableChanged ())
This commit is contained in:
parent
9f4fc7b323
commit
56544ac936
|
@ -457,7 +457,7 @@ bool isVariableChanged(const Token *start, const Token *end, const unsigned int
|
||||||
if (Token::simpleMatch(shr->astParent(), ">>"))
|
if (Token::simpleMatch(shr->astParent(), ">>"))
|
||||||
return true;
|
return true;
|
||||||
const Token *lhs = shr->astOperand1();
|
const Token *lhs = shr->astOperand1();
|
||||||
if (!lhs->valueType() || !lhs->valueType()->isIntegral())
|
if (!lhs || !lhs->valueType() || !lhs->valueType()->isIntegral())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ private:
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
TEST_CASE(isReturnScope);
|
TEST_CASE(isReturnScope);
|
||||||
|
TEST_CASE(isVariableChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isReturnScope(const char code[], int offset) {
|
bool isReturnScope(const char code[], int offset) {
|
||||||
|
@ -54,6 +55,25 @@ private:
|
||||||
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -4)); // #7144
|
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -4)); // #7144
|
||||||
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -2)); // #7144
|
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -2)); // #7144
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isVariableChanged(const char code[], const char startPattern[], const char endPattern[]) {
|
||||||
|
Settings settings;
|
||||||
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
std::istringstream istr(code);
|
||||||
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern);
|
||||||
|
const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern);
|
||||||
|
return ::isVariableChanged(tok1,tok2,1,false,&settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void isVariableChanged() {
|
||||||
|
// #8211 - no lhs for >> , do not crash
|
||||||
|
ASSERT_EQUALS(true,
|
||||||
|
isVariableChanged("void f() {\n"
|
||||||
|
" int b;\n"
|
||||||
|
" if (b) { (int)((INTOF(8))result >> b); }\n"
|
||||||
|
"}", "if", "}"));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestAstUtils)
|
REGISTER_TEST(TestAstUtils)
|
||||||
|
|
Loading…
Reference in New Issue