diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 419383699..4f61f102d 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 756e33269..c664a108a 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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