@@ -4384,6 +4384,41 @@ void CheckOther::overlappingWriteFunction(const Token *tok, const std::string& f
4384
4384
reportError (tok, Severity::error, " overlappingWriteFunction" , " Overlapping read/write in " + funcname + " () is undefined behavior" );
4385
4385
}
4386
4386
4387
+ void CheckOther::checkSuspiciousComma ()
4388
+ {
4389
+ if (!mSettings ->severity .isEnabled (Severity::style)) {
4390
+ return ;
4391
+ }
4392
+
4393
+ logChecker (" CheckOther::suspiciousComma" );
4394
+
4395
+ for (const Token* tok = mTokenizer ->list .front (); tok; tok = tok->next ()) {
4396
+ if (tok->str () == " ," && tok->isBinaryOp ()) {
4397
+ const Token * parent = tok->astParent ();
4398
+ if (parent && Token::Match (parent->previous (), " if|while (" )) {
4399
+ if (tok->strAt (-1 ) == " )" ) {
4400
+ const Function * func = tok->linkAt (-1 )->previous ()->function ();
4401
+ if (func && func->initArgCount > 0 ) {
4402
+ const Token * r_op = tok->astOperand2 ();
4403
+ if (r_op && (r_op->isVariable () ||
4404
+ r_op->tokType () == Token::eNumber ||
4405
+ r_op->tokType () == Token::eString ||
4406
+ r_op->tokType () == Token::eChar ||
4407
+ r_op->tokType () == Token::eBoolean)) {
4408
+ checkSuspiciousCommaError (tok);
4409
+ }
4410
+ }
4411
+ }
4412
+ }
4413
+ }
4414
+ }
4415
+ }
4416
+
4417
+ void CheckOther::checkSuspiciousCommaError (const Token *tok)
4418
+ {
4419
+ reportError (tok, Severity::style, " suspiciousComma" , " There is a suspicious comma expression in an if/while condition statement." );
4420
+ }
4421
+
4387
4422
void CheckOther::runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger)
4388
4423
{
4389
4424
CheckOther checkOther (&tokenizer, &tokenizer.getSettings (), errorLogger);
@@ -4431,6 +4466,7 @@ void CheckOther::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
4431
4466
checkOther.checkAccessOfMovedVariable ();
4432
4467
checkOther.checkModuloOfOne ();
4433
4468
checkOther.checkOverlappingWrite ();
4469
+ checkOther.checkSuspiciousComma ();
4434
4470
}
4435
4471
4436
4472
void CheckOther::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const
@@ -4503,6 +4539,7 @@ void CheckOther::getErrorMessages(ErrorLogger *errorLogger, const Settings *sett
4503
4539
c.comparePointersError (nullptr , nullptr , nullptr );
4504
4540
c.redundantAssignmentError (nullptr , nullptr , " var" , false );
4505
4541
c.redundantInitializationError (nullptr , nullptr , " var" , false );
4542
+ c.checkSuspiciousCommaError (nullptr );
4506
4543
4507
4544
const std::vector<const Token *> nullvec;
4508
4545
c.funcArgOrderDifferent (" function" , nullptr , nullptr , nullvec, nullvec);
0 commit comments