@@ -1437,6 +1437,11 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
14371437 return true ;
14381438 }
14391439
1440+ // bailout on ternary operator. TODO: This can be solved much better. For example, if the variable is not accessed in the branches of the ternary operator, we could just continue.
1441+ if (Token::Match (tok, " ?" )) {
1442+ return true ;
1443+ }
1444+
14401445 if (Token::Match (tok, " return|break|continue|throw|goto" )) {
14411446 if (noreturn)
14421447 *noreturn = true ;
@@ -1729,16 +1734,16 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
17291734 if (arg) {
17301735 const bool address (vartok->previous ()->str () == " &" );
17311736 const Token *argStart = arg->typeStartToken ();
1732- while (argStart->previous () && argStart->previous ()->isName ())
1733- argStart = argStart->previous ();
1734- if (!address && Token::Match (argStart, " const| struct| %type% [,)]" ))
1735- return true ;
1736- if (!address && Token::Match (argStart, " const| struct| %type% %var% [,)]" ))
1737+ if (!address && Token::Match (argStart, " struct| %type% [,)]" ))
17371738 return true ;
1738- if (Token::Match (argStart, " const %type% & %var% [,)]" ))
1739+ if (!address && Token::Match (argStart, " struct| %type% %var% [,)]" ))
17391740 return true ;
17401741 if (pointer && !address && !alloc && Token::Match (argStart, " struct| %type% * %var% [,)]" ))
17411742 return true ;
1743+ while (argStart->previous () && argStart->previous ()->isName ())
1744+ argStart = argStart->previous ();
1745+ if (Token::Match (argStart, " const %type% & %var% [,)]" ))
1746+ return true ;
17421747 if ((pointer || address) && !alloc && Token::Match (argStart, " const struct| %type% * %var% [,)]" ))
17431748 return true ;
17441749 if ((pointer || address) && Token::Match (argStart, " const %type% %var% [" ) && Token::Match (argStart->linkAt (3 ), " ] [,)]" ))
@@ -1748,6 +1753,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
17481753 } else if (Token::Match (start->previous (), " if|while|for" )) {
17491754 // control-flow statement reading the variable "by value"
17501755 return !alloc;
1756+ } else {
1757+ bool isnullbad = _settings->library .isnullargbad (start->previous (), argumentNumber + 1 );
1758+ bool isuninitbad = _settings->library .isuninitargbad (start->previous (), argumentNumber + 1 );
1759+ if (alloc)
1760+ return isnullbad && isuninitbad;
1761+ return isuninitbad;
17511762 }
17521763 }
17531764 }
0 commit comments