Skip to content

Commit e837bad

Browse files
committed
Fixed false positive in new stringLiteralWrite checker
1 parent 6b80e61 commit e837bad

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

lib/checkstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace {
3535
void CheckString::stringLiteralWrite()
3636
{
3737
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
38-
if (!tok->variable())
38+
if (!tok->variable() || !tok->variable()->isPointer())
3939
continue;
4040
const Token *str = tok->getValueTokenMinStrSize();
4141
if (!str)

test/teststring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class TestString : public TestFixture {
111111
ASSERT_EQUALS("[test.cpp:3]: (error) Modifying string literal directly or indirectly is undefined behaviour\n", errout.str());
112112

113113
check("void f() {\n"
114-
" char *abc = \"abc\";\n"
115-
" if (*abc == 'a'){}\n"
114+
" QString abc = \"abc\";\n"
115+
" abc[0] = 'a';\n"
116116
"}");
117117
ASSERT_EQUALS("", errout.str());
118118
}

0 commit comments

Comments
 (0)