CheckAutoVariables: Handle 'x-y' better in isAutoVarArray

This commit is contained in:
Daniel Marjamäki 2015-11-15 19:34:36 +01:00
parent 65666a1ba4
commit 71bf0f076f
2 changed files with 13 additions and 0 deletions

View File

@ -99,6 +99,13 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok)
if (tok->str() == "+") if (tok->str() == "+")
return isAutoVarArray(tok->astOperand1()) || isAutoVarArray(tok->astOperand2()); return isAutoVarArray(tok->astOperand1()) || isAutoVarArray(tok->astOperand2());
// x-intexpr
if (tok->str() == "-")
return isAutoVarArray(tok->astOperand1()) &&
tok->astOperand2() &&
tok->astOperand2()->valueType() &&
tok->astOperand2()->valueType()->isIntegral();
const Variable *var = tok->variable(); const Variable *var = tok->variable();
if (!var) if (!var)
return false; return false;

View File

@ -680,6 +680,12 @@ private:
" return x+5;\n" " return x+5;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Pointer to local array variable returned.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Pointer to local array variable returned.\n", errout.str());
check("char *foo(int y) {\n"
" char x[10] = {0};\n"
" return (x+8)-y;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Pointer to local array variable returned.\n", errout.str());
} }
void returnLocalVariable5() { // cast void returnLocalVariable5() { // cast