diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index bdbdee994..74cd99d43 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -35,7 +35,7 @@ namespace { void CheckString::stringLiteralWrite() { for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (!tok->variable()) + if (!tok->variable() || !tok->variable()->isPointer()) continue; const Token *str = tok->getValueTokenMinStrSize(); if (!str) diff --git a/test/teststring.cpp b/test/teststring.cpp index 705f97400..2ee9da3f9 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -111,8 +111,8 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Modifying string literal directly or indirectly is undefined behaviour\n", errout.str()); check("void f() {\n" - " char *abc = \"abc\";\n" - " if (*abc == 'a'){}\n" + " QString abc = \"abc\";\n" + " abc[0] = 'a';\n" "}"); ASSERT_EQUALS("", errout.str()); }