@@ -4367,6 +4367,33 @@ void CheckOther::overlappingWriteFunction(const Token *tok, const std::string& f
4367
4367
reportError (tok, Severity::error, " overlappingWriteFunction" , " Overlapping read/write in " + funcname + " () is undefined behavior" );
4368
4368
}
4369
4369
4370
+ void CheckOther::checkSuspiciousComma ()
4371
+ {
4372
+ if (!mSettings ->severity .isEnabled (Severity::style)) {
4373
+ return ;
4374
+ }
4375
+
4376
+ logChecker (" CheckOpComma::warnSuspiciousComma" );
4377
+
4378
+ for (const Token* tok = mTokenizer ->list .front (); tok; tok = tok->next ()) {
4379
+ if (tok->str () == " ," && tok->isBinaryOp ()) {
4380
+ const Token * parent = tok->astParent ();
4381
+ if (parent && (Token::simpleMatch (parent->previous (), " if (" ) ||
4382
+ Token::simpleMatch (parent->previous (), " while (" ))) {
4383
+ if (tok->previous ()->str () == " )" && tok->previous ()->link ()->str () == " (" ) {
4384
+ const Function * func = tok->previous ()->link ()->previous ()->function ();
4385
+ if (func && func->initArgCount > 0 ) {
4386
+ const Token * r_op = tok->astOperand2 ();
4387
+ if (r_op && r_op->hasKnownValue ()) {
4388
+ reportError (tok, Severity::style, " warnSuspiciousComma" , " There is an suspicious comma expression used as a condition." );
4389
+ }
4390
+ }
4391
+ }
4392
+ }
4393
+ }
4394
+ }
4395
+ }
4396
+
4370
4397
void CheckOther::runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger)
4371
4398
{
4372
4399
CheckOther checkOther (&tokenizer, &tokenizer.getSettings (), errorLogger);
@@ -4414,6 +4441,7 @@ void CheckOther::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
4414
4441
checkOther.checkAccessOfMovedVariable ();
4415
4442
checkOther.checkModuloOfOne ();
4416
4443
checkOther.checkOverlappingWrite ();
4444
+ checkOther.checkSuspiciousComma ();
4417
4445
}
4418
4446
4419
4447
void CheckOther::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const
0 commit comments