MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkModuloOfOne

Method checkModuloOfOne

lib/checkother.cpp:4465–4485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4463}
4464
4465void CheckOtherImpl::checkModuloOfOne()
4466{
4467 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("moduloofone"))
4468 return;
4469
4470 logChecker("CheckOther::checkModuloOfOne"); // style
4471
4472 for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
4473 if (!tok->astOperand2() || !tok->astOperand1())
4474 continue;
4475 if (tok->str() != "%" && tok->str() != "%=")
4476 continue;
4477 if (!tok->valueType() || !tok->valueType()->isIntegral())
4478 continue;
4479
4480 // Value flow..
4481 const ValueFlow::Value *value = tok->astOperand2()->getValue(1LL);
4482 if (value && value->isKnown())
4483 checkModuloOfOneError(tok);
4484 }
4485}
4486
4487void CheckOtherImpl::checkModuloOfOneError(const Token *tok)
4488{

Callers 1

runChecksMethod · 0.80

Calls 9

isPremiumEnabledMethod · 0.80
nextMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
isIntegralMethod · 0.80
isKnownMethod · 0.80
isEnabledMethod · 0.45
strMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected