Merge pull request #171 from simartin/ticket_5024

Ticket #5024: Don't crash upon invalid code when checking auto variables
This commit is contained in:
Daniel Marjamäki 2013-09-27 21:25:40 -07:00
commit e5843b32c4
2 changed files with 8 additions and 0 deletions

View File

@ -101,6 +101,9 @@ static bool checkRvalueExpression(const Token * const vartok)
static bool variableIsUsedInScope(const Token* start, unsigned int varId, const Scope *scope) static bool variableIsUsedInScope(const Token* start, unsigned int varId, const Scope *scope)
{ {
if(!start) // Ticket #5024
return false;
for (const Token *tok = start; tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = start; tok != scope->classEnd; tok = tok->next()) {
if (tok->varId() == varId) if (tok->varId() == varId)
return true; return true;

View File

@ -78,6 +78,7 @@ private:
TEST_CASE(testautovar9); TEST_CASE(testautovar9);
TEST_CASE(testautovar10); // ticket #2930 - void f(char *p) { p = '\0'; } TEST_CASE(testautovar10); // ticket #2930 - void f(char *p) { p = '\0'; }
TEST_CASE(testautovar11); // ticket #4641 - fp, assign local struct member address to function parameter TEST_CASE(testautovar11); // ticket #4641 - fp, assign local struct member address to function parameter
TEST_CASE(testautovar12); // ticket #5024 - crash
TEST_CASE(testautovar_array1); TEST_CASE(testautovar_array1);
TEST_CASE(testautovar_array2); TEST_CASE(testautovar_array2);
TEST_CASE(testautovar_return1); TEST_CASE(testautovar_return1);
@ -326,6 +327,10 @@ private:
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
} }
void testautovar12() { // Ticket #5024 - Crash on invalid input
check("void f(int* a) { a = }");
}
void testautovar_array1() { void testautovar_array1() {
check("void func1(int* arr[2])\n" check("void func1(int* arr[2])\n"
"{\n" "{\n"