@@ -1307,6 +1307,25 @@ void CheckOther::commaSeparatedReturnError(const Token *tok)
13071307 " macro is then used in a return statement, it is less likely such code is misunderstood." , CWE398, Certainty::normal);
13081308}
13091309
1310+ static bool isLargeContainer (const Variable* var, const Settings* settings)
1311+ {
1312+ const ValueType* vt = var->valueType ();
1313+ if (vt->container ->size_templateArgNo < 0 )
1314+ return true ;
1315+ const std::size_t maxByValueSize = 2 * settings->platform .sizeof_pointer ;
1316+ if (var->dimensions ().empty ()) {
1317+ if (vt->container ->startPattern == " std :: bitset <" ) {
1318+ if (vt->containerTypeToken ->hasKnownIntValue ())
1319+ return vt->containerTypeToken ->getKnownIntValue () / 8 > maxByValueSize;
1320+ }
1321+ return false ;
1322+ }
1323+ const ValueType vtElem = ValueType::parseDecl (vt->containerTypeToken , *settings);
1324+ const auto elemSize = std::max<std::size_t >(ValueFlow::getSizeOf (vtElem, *settings), 1 );
1325+ const auto arraySize = var->dimension (0 ) * elemSize;
1326+ return arraySize > maxByValueSize;
1327+ }
1328+
13101329void CheckOther::checkPassByReference ()
13111330{
13121331 if (!mSettings ->severity .isEnabled (Severity::performance) || mTokenizer ->isC ())
@@ -1317,7 +1336,7 @@ void CheckOther::checkPassByReference()
13171336 const SymbolDatabase * const symbolDatabase = mTokenizer ->getSymbolDatabase ();
13181337
13191338 for (const Variable* var : symbolDatabase->variableList ()) {
1320- if (!var || !var->isClass () || var->isPointer () || var->isArray () || var->isReference () || var->isEnumType ())
1339+ if (!var || !var->isClass () || var->isPointer () || ( var->isArray () && !var-> isStlType () ) || var->isReference () || var->isEnumType ())
13211340 continue ;
13221341
13231342 const bool isRangeBasedFor = astIsRangeBasedForDecl (var->nameToken ());
@@ -1335,6 +1354,8 @@ void CheckOther::checkPassByReference()
13351354 bool inconclusive = false ;
13361355
13371356 const bool isContainer = var->valueType () && var->valueType ()->type == ValueType::Type::CONTAINER && var->valueType ()->container && !var->valueType ()->container ->view ;
1357+ if (isContainer && !isLargeContainer (var, mSettings ))
1358+ continue ;
13381359 if (!isContainer) {
13391360 if (var->type () && !var->type ()->isEnumType ()) { // Check if type is a struct or class.
13401361 // Ensure that it is a large object.
0 commit comments