@@ -4387,6 +4387,43 @@ void CheckOther::overlappingWriteFunction(const Token *tok, const std::string& f
43874387 reportError (tok, Severity::error, " overlappingWriteFunction" , " Overlapping read/write in " + funcname + " () is undefined behavior" );
43884388}
43894389
4390+ void CheckOther::checkSuspiciousComma ()
4391+ {
4392+ if (!mSettings ->severity .isEnabled (Severity::style)) {
4393+ return ;
4394+ }
4395+
4396+ logChecker (" CheckOther::suspiciousComma" );
4397+
4398+ for (const Token* tok = mTokenizer ->list .front (); tok; tok = tok->next ()) {
4399+ if (tok->str () == " ," && tok->isBinaryOp ()) {
4400+ const Token * parent = tok->astParent ();
4401+ if (parent && Token::Match (parent->previous (), " if|while (" )) {
4402+ if (tok->strAt (-1 ) == " )" ) {
4403+ const Function * func = tok->linkAt (-1 )->previous ()->function ();
4404+ if (func && func->initArgCount > 0 && !tok->astOperand2 ()->hasKnownValue ()) {
4405+ std::vector<const Token*> arg_vec = getArguments (tok->linkAt (-1 )->previous ());
4406+ if (arg_vec.size () < func->argCount () && arg_vec.size () > 0 ) {
4407+ const ValueType * type1 = tok->astOperand2 ()->valueType ();
4408+ std::vector<Variable> v (func->argumentList .begin (), func->argumentList .end ());
4409+ const ValueType * type2 = v[arg_vec.size ()].valueType ();
4410+ if (type1 && type2 && type1->isTypeEqual (type2)) {
4411+ checkSuspiciousCommaError (tok);
4412+ }
4413+ }
4414+ }
4415+ }
4416+ }
4417+ }
4418+ }
4419+ }
4420+
4421+ void CheckOther::checkSuspiciousCommaError (const Token *tok)
4422+ {
4423+ reportError (tok, Severity::style, " suspiciousComma" , " There is a suspicious comma expression directly after a function call "
4424+ " in an if/while condition statement, is there a misplaced paranthesis?" );
4425+ }
4426+
43904427void CheckOther::runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger)
43914428{
43924429 CheckOther checkOther (&tokenizer, &tokenizer.getSettings (), errorLogger);
@@ -4434,6 +4471,7 @@ void CheckOther::runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
44344471 checkOther.checkAccessOfMovedVariable ();
44354472 checkOther.checkModuloOfOne ();
44364473 checkOther.checkOverlappingWrite ();
4474+ checkOther.checkSuspiciousComma ();
44374475}
44384476
44394477void CheckOther::getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const
@@ -4506,6 +4544,7 @@ void CheckOther::getErrorMessages(ErrorLogger *errorLogger, const Settings *sett
45064544 c.comparePointersError (nullptr , nullptr , nullptr );
45074545 c.redundantAssignmentError (nullptr , nullptr , " var" , false );
45084546 c.redundantInitializationError (nullptr , nullptr , " var" , false );
4547+ c.checkSuspiciousCommaError (nullptr );
45094548
45104549 const std::vector<const Token *> nullvec;
45114550 c.funcArgOrderDifferent (" function" , nullptr , nullptr , nullvec, nullvec);
0 commit comments