Fixed #5857 (strPlusChar: Crash on invalid code 'int+;')
This commit is contained in:
parent
86dede14c0
commit
66ad3c97b9
|
@ -2182,12 +2182,11 @@ void CheckOther::strPlusChar()
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (std::size_t i = 0; i < functions; ++i) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->str() == "+" && tok->astOperand2()) {
|
if (tok->str() == "+") {
|
||||||
if (tok->astOperand1()->type() == Token::eString) { // string literal...
|
if (tok->astOperand1() && (tok->astOperand1()->type() == Token::eString)) { // string literal...
|
||||||
if (tok->astOperand2() && (tok->astOperand2()->type() == Token::eChar || isChar(tok->astOperand2()->variable()))) // added to char variable or char constant
|
if (tok->astOperand2() && (tok->astOperand2()->type() == Token::eChar || isChar(tok->astOperand2()->variable()))) // added to char variable or char constant
|
||||||
strPlusCharError(tok);
|
strPlusCharError(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ private:
|
||||||
TEST_CASE(strPlusChar1); // "/usr" + '/'
|
TEST_CASE(strPlusChar1); // "/usr" + '/'
|
||||||
TEST_CASE(strPlusChar2); // "/usr" + ch
|
TEST_CASE(strPlusChar2); // "/usr" + ch
|
||||||
TEST_CASE(strPlusChar3); // ok: path + "/sub" + '/'
|
TEST_CASE(strPlusChar3); // ok: path + "/sub" + '/'
|
||||||
|
TEST_CASE(strPlusChar4); // ast
|
||||||
|
|
||||||
TEST_CASE(varScope1);
|
TEST_CASE(varScope1);
|
||||||
TEST_CASE(varScope2);
|
TEST_CASE(varScope2);
|
||||||
|
@ -901,6 +902,10 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strPlusChar4() {
|
||||||
|
// don't crash
|
||||||
|
strPlusChar("int test() { int +; }");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void varScope(const char code[]) {
|
void varScope(const char code[]) {
|
||||||
|
|
Loading…
Reference in New Issue