diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e140d965114..2330a9d2b94 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2499,7 +2499,7 @@ bool isMutableExpression(const Token* tok) if (const Variable* var = tok->variable()) { if (var->nameToken() == tok) return false; - if (!var->isPointer() && var->isConst()) + if (var->isConst() && !var->isPointer() && (!var->isArray() || !var->isArgument())) return false; } return true; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index f2664b05285..37107397a44 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -995,6 +995,14 @@ class TestNullPointer : public TestFixture { "char f(S* s) { return s->p ? 'a' : s->p->c; }\n"); ASSERT_EQUALS("[test.cpp:2:24] -> [test.cpp:2:37]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: s->p. [nullPointerRedundantCheck]\n", errout_str()); + + check("int f(const int a[]) {\n" // #14544 + " int i = 0;\n" + " if (!a)\n" + " a = &i;\n" + " return *a;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void nullpointer5() {