@@ -143,14 +143,14 @@ static bool isAutoVarArray(const Token *tok)
143
143
return false ;
144
144
}
145
145
146
- static bool isLocalContainerBuffer (const Token* tok)
146
+ static bool isLocalContainerBuffer (const Token* tok, const Settings& settings )
147
147
{
148
148
if (!tok)
149
149
return false ;
150
150
151
151
// x+y
152
152
if (tok->str () == " +" )
153
- return isLocalContainerBuffer (tok->astOperand1 ()) || isLocalContainerBuffer (tok->astOperand2 ());
153
+ return isLocalContainerBuffer (tok->astOperand1 (), settings ) || isLocalContainerBuffer (tok->astOperand2 (), settings );
154
154
155
155
if (tok->str () != " (" || !Token::simpleMatch (tok->astOperand1 (), " ." ))
156
156
return false ;
@@ -161,7 +161,7 @@ static bool isLocalContainerBuffer(const Token* tok)
161
161
if (!var || !var->isLocal () || var->isStatic ())
162
162
return false ;
163
163
164
- const Library::Container::Yield yield = astContainerYield (tok);
164
+ const Library::Container::Yield yield = astContainerYield (tok, settings. library );
165
165
166
166
return yield == Library::Container::Yield::BUFFER || yield == Library::Container::Yield::BUFFER_NT;
167
167
}
@@ -237,8 +237,8 @@ void CheckAutoVariables::assignFunctionArg()
237
237
}
238
238
}
239
239
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 );
242
242
}
243
243
244
244
static bool hasOverloadedAssignment (const Token* tok, bool & inconclusive)
@@ -275,23 +275,23 @@ void CheckAutoVariables::autoVariables()
275
275
continue ;
276
276
}
277
277
// 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 )) {
279
279
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 )) {
281
281
const Token* lhs = tok->tokAt (2 );
282
282
bool inconclusive = false ;
283
283
if (!hasOverloadedAssignment (lhs, inconclusive) || (printInconclusive && inconclusive))
284
284
checkAutoVariableAssignment (tok->next (), inconclusive);
285
285
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 )) {
287
287
const Token* lhs = tok->tokAt (3 );
288
288
bool inconclusive = false ;
289
289
if (!hasOverloadedAssignment (lhs, inconclusive) || (printInconclusive && inconclusive))
290
290
checkAutoVariableAssignment (tok->next (), inconclusive);
291
291
tok = tok->tokAt (5 );
292
292
} else if (Token::Match (tok, " [;{}] %var% [" ) && Token::simpleMatch (tok->linkAt (2 ), " ] =" ) &&
293
293
(isPtrArg (tok->next ()) || isArrayArg (tok->next (), *mSettings )) &&
294
- isAutoVariableRHS (tok->linkAt (2 )->next ()->astOperand2 ())) {
294
+ isAutoVariableRHS (tok->linkAt (2 )->next ()->astOperand2 (), * mSettings )) {
295
295
errorAutoVariableAssignment (tok->next (), false );
296
296
}
297
297
// Invalid pointer deallocation
0 commit comments