@@ -143,14 +143,14 @@ static bool isAutoVarArray(const Token *tok)
143143 return false ;
144144}
145145
146- static bool isLocalContainerBuffer (const Token* tok)
146+ static bool isLocalContainerBuffer (const Token* tok, const Settings& settings )
147147{
148148 if (!tok)
149149 return false ;
150150
151151 // x+y
152152 if (tok->str () == " +" )
153- return isLocalContainerBuffer (tok->astOperand1 ()) || isLocalContainerBuffer (tok->astOperand2 ());
153+ return isLocalContainerBuffer (tok->astOperand1 (), settings ) || isLocalContainerBuffer (tok->astOperand2 (), settings );
154154
155155 if (tok->str () != " (" || !Token::simpleMatch (tok->astOperand1 (), " ." ))
156156 return false ;
@@ -161,7 +161,7 @@ static bool isLocalContainerBuffer(const Token* tok)
161161 if (!var || !var->isLocal () || var->isStatic ())
162162 return false ;
163163
164- const Library::Container::Yield yield = astContainerYield (tok);
164+ const Library::Container::Yield yield = astContainerYield (tok, settings. library );
165165
166166 return yield == Library::Container::Yield::BUFFER || yield == Library::Container::Yield::BUFFER_NT;
167167}
@@ -237,8 +237,8 @@ void CheckAutoVariables::assignFunctionArg()
237237 }
238238}
239239
240- static bool isAutoVariableRHS (const Token* tok) {
241- return isAddressOfLocalVariable (tok) || isAutoVarArray (tok) || isLocalContainerBuffer (tok);
240+ static bool isAutoVariableRHS (const Token* tok, const Settings& settings ) {
241+ return isAddressOfLocalVariable (tok) || isAutoVarArray (tok) || isLocalContainerBuffer (tok, settings );
242242}
243243
244244static bool hasOverloadedAssignment (const Token* tok, bool & inconclusive)
@@ -275,23 +275,23 @@ void CheckAutoVariables::autoVariables()
275275 continue ;
276276 }
277277 // Critical assignment
278- if (Token::Match (tok, " [;{}] %var% =" ) && isRefPtrArg (tok->next ()) && isAutoVariableRHS (tok->tokAt (2 )->astOperand2 ())) {
278+ if (Token::Match (tok, " [;{}] %var% =" ) && isRefPtrArg (tok->next ()) && isAutoVariableRHS (tok->tokAt (2 )->astOperand2 (), * mSettings )) {
279279 checkAutoVariableAssignment (tok->next (), false );
280- } else if (Token::Match (tok, " [;{}] * %var% =" ) && isPtrArg (tok->tokAt (2 )) && isAutoVariableRHS (tok->tokAt (3 )->astOperand2 ())) {
280+ } else if (Token::Match (tok, " [;{}] * %var% =" ) && isPtrArg (tok->tokAt (2 )) && isAutoVariableRHS (tok->tokAt (3 )->astOperand2 (), * mSettings )) {
281281 const Token* lhs = tok->tokAt (2 );
282282 bool inconclusive = false ;
283283 if (!hasOverloadedAssignment (lhs, inconclusive) || (printInconclusive && inconclusive))
284284 checkAutoVariableAssignment (tok->next (), inconclusive);
285285 tok = tok->tokAt (4 );
286- } else if (Token::Match (tok, " [;{}] %var% . %var% =" ) && isPtrArg (tok->next ()) && isAutoVariableRHS (tok->tokAt (4 )->astOperand2 ())) {
286+ } else if (Token::Match (tok, " [;{}] %var% . %var% =" ) && isPtrArg (tok->next ()) && isAutoVariableRHS (tok->tokAt (4 )->astOperand2 (), * mSettings )) {
287287 const Token* lhs = tok->tokAt (3 );
288288 bool inconclusive = false ;
289289 if (!hasOverloadedAssignment (lhs, inconclusive) || (printInconclusive && inconclusive))
290290 checkAutoVariableAssignment (tok->next (), inconclusive);
291291 tok = tok->tokAt (5 );
292292 } else if (Token::Match (tok, " [;{}] %var% [" ) && Token::simpleMatch (tok->linkAt (2 ), " ] =" ) &&
293293 (isPtrArg (tok->next ()) || isArrayArg (tok->next (), *mSettings )) &&
294- isAutoVariableRHS (tok->linkAt (2 )->next ()->astOperand2 ())) {
294+ isAutoVariableRHS (tok->linkAt (2 )->next ()->astOperand2 (), * mSettings )) {
295295 errorAutoVariableAssignment (tok->next (), false );
296296 }
297297 // Invalid pointer deallocation
0 commit comments