Skip to content

Commit f73da16

Browse files
committed
Revert "UninitVar: Better checking in whole program analysis"
This reverts commit b2bdc26.
1 parent b2bdc26 commit f73da16

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

lib/checkuninitvar.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,10 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
937937
}
938938

939939
if (Token::Match(vartok->previous(), "++|--|%cop%")) {
940-
if ((!_tokenizer || _tokenizer->isCPP()) && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
940+
if (_tokenizer->isCPP() && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
941941
return false;
942942

943-
if (_tokenizer && _tokenizer->isCPP() && Token::Match(vartok->previous(), ">>|<<")) {
943+
if (_tokenizer->isCPP() && Token::Match(vartok->previous(), ">>|<<")) {
944944
const Token* tok2 = vartok->previous();
945945
if (Token::simpleMatch(tok2->astOperand1(), ">>"))
946946
return false; // Looks like stream operator, initializes the variable
@@ -1012,7 +1012,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
10121012
return true;
10131013
}
10141014

1015-
if (_tokenizer && _tokenizer->isCPP() && Token::Match(vartok->next(), "<<|>>")) {
1015+
if (_tokenizer->isCPP() && Token::Match(vartok->next(), "<<|>>")) {
10161016
// Is this calculation done in rhs?
10171017
const Token *tok = vartok;
10181018
while (Token::Match(tok, "%name%|.|::"))
@@ -1320,15 +1320,19 @@ CheckUninitVar::MyFileInfo::FunctionArg::FunctionArg(const Tokenizer *tokenizer,
13201320
location.linenr = tok->linenr();
13211321
}
13221322

1323-
bool CheckUninitVar::isUnsafeFunction(const Scope *scope, int argnr, const Token **tok) const
1323+
static bool isUnsafeFunction(const Scope *scope, int argnr, const Token **tok)
13241324
{
13251325
const Variable * const argvar = scope->function->getArgumentVar(argnr);
13261326
if (!argvar->isPointer())
13271327
return false;
13281328
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
13291329
if (tok2->variable() != argvar)
13301330
continue;
1331-
if (!isVariableUsage(tok2, true, Alloc::ARRAY))
1331+
if (!Token::Match(tok2->astParent(), "*|["))
1332+
return false;
1333+
while (Token::Match(tok2->astParent(), "*|["))
1334+
tok2 = tok2->astParent();
1335+
if (!Token::Match(tok2->astParent(),"%cop%"))
13321336
return false;
13331337
*tok = tok2;
13341338
return true;

lib/checkuninitvar.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ class CPPCHECKLIB CheckUninitVar : public Check {
155155
void uninitStructMemberError(const Token *tok, const std::string &membername);
156156

157157
private:
158-
bool isUnsafeFunction(const Scope *scope, int argnr, const Token **tok) const;
159-
160158
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
161159
CheckUninitVar c(nullptr, settings, errorLogger);
162160

test/testuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3996,7 +3996,7 @@ class TestUninitVar : public TestFixture {
39963996

39973997
void ctu() {
39983998
ctu("void f(int *p) {\n"
3999-
" a = *p;\n"
3999+
" a = *p + 3;\n"
40004000
"}\n"
40014001
"int main() {\n"
40024002
" int x;\n"

0 commit comments

Comments
 (0)