Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable* const vari

else if (tok3->str() == "}") {
if (indentlevel3 == 0) {
memoryLeak(tok3, variable->name() + "." + assignToks.first->str(), allocType);
memoryLeak(tok3, variable->name() + "." + tok2->strAt(2), allocType);
break;
}
--indentlevel3;
Expand Down
3 changes: 2 additions & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,8 @@ void CheckUninitVar::valueFlowUninit()
const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, *mSettings);
uninitderef = deref && v->indirect == 0;
const bool isleaf = isLeafDot(tok) || uninitderef;
if (!isleaf && Token::Match(tok->astParent(), ". %name%") && (tok->astParent()->next()->varId() || tok->astParent()->next()->isEnumerator()))
if (!isleaf && Token::Match(tok->astParent(), ". %name%") &&
(tok->astParent()->next()->variable() || tok->astParent()->next()->isEnumerator()))
continue;
}
const ExprUsage usage = getExprUsage(tok, v->indirect, *mSettings);
Expand Down
13 changes: 11 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3546,8 +3546,17 @@ void Tokenizer::combineOperators()
tok->deleteNext();
}
} else if (tok->str() == "->") {
tok->str(".");
tok->originalName("->");
// If the preceding sequence is "( & %name% )", replace it by "%name%"
Token* t = tok->tokAt(-4);
if (Token::Match(t, "( & %name% )") && !Token::simpleMatch(t->previous(), ">")) {
t->deleteThis();
t->deleteThis();
t->deleteNext();
tok->str(".");
} else {
tok->str(".");
tok->originalName("->");
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ssize_t nullPointer_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t o
return pwritev(fd,iov,iovcnt,offset);
}

// #9346
// False negative: #9346
void uninitvar_timercmp(struct timeval t)
{
struct timeval uninit;
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ void uninitvar_types(void)
b + 1;

struct dirent d;
// cppcheck-suppress constStatement - TODO: uninitvar
// cppcheck-suppress [uninitvar,constStatement]
d.d_ino + 1;
}

Expand Down
16 changes: 16 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7632,6 +7632,22 @@ class TestUninitVar : public TestFixture {
" S s{ d };\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: d\n", errout_str());

valueFlowUninit("struct S { int x; int y; };\n"
"int f() {\n"
" S s;\n"
" s.x = 0;\n"
" return (&s)->x;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

valueFlowUninit("struct S { int x; int y; };\n"
"int f() {\n"
" S s;\n"
" s.x = 0;\n"
" return (&s)->y;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s.y\n", errout_str());
}

void valueFlowUninitForLoop()
Expand Down
2 changes: 1 addition & 1 deletion test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class TestVarID : public TestFixture {

const char expected[] = "1: struct S { int i@1 ; } ;\n"
"2: int f ( S s@2 ) {\n"
"3: return ( & s@2 ) . i@3 ;\n"
"3: return s@2 . i@3 ;\n"
"4: }\n";

ASSERT_EQUALS(expected, actual);
Expand Down
Loading