CheckAutoVariables: Handle 'x-y' better in isAutoVarArray
This commit is contained in:
parent
65666a1ba4
commit
71bf0f076f
|
@ -99,6 +99,13 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok)
|
|||
if (tok->str() == "+")
|
||||
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();
|
||||
if (!var)
|
||||
return false;
|
||||
|
|
|
@ -680,6 +680,12 @@ private:
|
|||
" return x+5;\n"
|
||||
"}");
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue