Formatting

This commit is contained in:
Paul 2020-09-08 21:55:53 -05:00
parent 382408f59e
commit 965fea370f
3 changed files with 12 additions and 9 deletions

View File

@ -5953,12 +5953,13 @@ static void valueFlowSmartPointer(TokenList *tokenlist, ErrorLogger * errorLogge
if (!tok->scope()->isExecutable()) if (!tok->scope()->isExecutable())
continue; continue;
if (tok->variable()) { if (tok->variable()) {
const Variable * var = tok->variable(); const Variable* var = tok->variable();
if (!var->isSmartPointer()) if (!var->isSmartPointer())
continue; continue;
if (var->nameToken() == tok) { if (var->nameToken() == tok) {
if (Token::Match(tok, "%var% (|{") && tok->next()->astOperand2() && tok->next()->astOperand2()->str() != ",") { if (Token::Match(tok, "%var% (|{") && tok->next()->astOperand2() &&
Token * inTok = tok->next()->astOperand2(); tok->next()->astOperand2()->str() != ",") {
Token* inTok = tok->next()->astOperand2();
std::list<ValueFlow::Value> values = inTok->values(); std::list<ValueFlow::Value> values = inTok->values();
const bool constValue = inTok->isNumber(); const bool constValue = inTok->isNumber();
valueFlowForwardAssign(inTok, var, values, constValue, true, tokenlist, errorLogger, settings); valueFlowForwardAssign(inTok, var, values, constValue, true, tokenlist, errorLogger, settings);
@ -5979,7 +5980,7 @@ static void valueFlowSmartPointer(TokenList *tokenlist, ErrorLogger * errorLogge
valueFlowForwardAssign(tok->tokAt(4), var, values, false, false, tokenlist, errorLogger, settings); valueFlowForwardAssign(tok->tokAt(4), var, values, false, false, tokenlist, errorLogger, settings);
} else { } else {
tok->removeValues(std::mem_fn(&ValueFlow::Value::isIntValue)); tok->removeValues(std::mem_fn(&ValueFlow::Value::isIntValue));
Token * inTok = tok->tokAt(3)->astOperand2(); Token* inTok = tok->tokAt(3)->astOperand2();
if (!inTok) if (!inTok)
continue; continue;
std::list<ValueFlow::Value> values = inTok->values(); std::list<ValueFlow::Value> values = inTok->values();
@ -5993,11 +5994,12 @@ static void valueFlowSmartPointer(TokenList *tokenlist, ErrorLogger * errorLogge
values.push_back(v); values.push_back(v);
valueFlowForwardAssign(tok->tokAt(4), var, values, false, false, tokenlist, errorLogger, settings); valueFlowForwardAssign(tok->tokAt(4), var, values, false, false, tokenlist, errorLogger, settings);
} }
} else if (Token::Match(tok->previous(), "%name%|> (|{") && astIsSmartPointer(tok) && astIsSmartPointer(tok->astOperand1())) { } else if (Token::Match(tok->previous(), "%name%|> (|{") && astIsSmartPointer(tok) &&
astIsSmartPointer(tok->astOperand1())) {
std::vector<const Token*> args = getArguments(tok); std::vector<const Token*> args = getArguments(tok);
if (args.empty()) if (args.empty())
continue; continue;
for(const ValueFlow::Value& v:args.front()->values()) for (const ValueFlow::Value& v : args.front()->values())
setTokenValue(tok, v, settings); setTokenValue(tok, v, settings);
} }
} }

View File

@ -2866,7 +2866,8 @@ private:
"}\n" "}\n"
"void g() {\n" "void g() {\n"
" int a = *f();\n" " int a = *f();\n"
"}\n", true); "}\n",
true);
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f()\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f()\n", errout.str());
} }

View File

@ -1153,8 +1153,8 @@ private:
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
ASSERT_EQUALS_WITHOUT_LINENUMBERS( ASSERT_EQUALS_WITHOUT_LINENUMBERS(
"[test.cpp:31]: (debug) valueflow.cpp:3109:valueFlowFunctionReturn bailout: function return; nontrivial function body\n" "[test.cpp:31]: (debug) valueflow.cpp:3109:valueFlowFunctionReturn bailout: function return; nontrivial function body\n"
"[test.cpp:28]: (debug) valueflow.cpp:3109:valueFlowFunctionReturn bailout: function return; nontrivial function body\n" "[test.cpp:28]: (debug) valueflow.cpp:3109:valueFlowFunctionReturn bailout: function return; nontrivial function body\n",
, errout.str()); errout.str());
} }
void simplifyTypedef36() { void simplifyTypedef36() {