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

Function valueFlowArrayBool

lib/valueflow.cpp:708–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706}
707
708static void valueFlowArrayBool(TokenList& tokenlist, const Settings& settings)
709{
710 for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
711 if (tok->hasKnownIntValue())
712 continue;
713 const Variable* var = nullptr;
714 bool known = false;
715 const auto val =
716 std::find_if(tok->values().cbegin(), tok->values().cend(), std::mem_fn(&ValueFlow::Value::isTokValue));
717 if (val == tok->values().end()) {
718 var = tok->variable();
719 known = true;
720 } else {
721 var = val->tokvalue->variable();
722 known = val->isKnown();
723 }
724 if (!var)
725 continue;
726 if (!var->isArray() || var->isArgument() || var->isStlType())
727 continue;
728 if (isNonZero(getOtherOperand(tok)) && Token::Match(tok->astParent(), "%comp%"))
729 continue;
730 // TODO: Check for function argument
731 if ((astIsBool(tok->astParent()) && !Token::Match(tok->astParent(), "(|%name%")) ||
732 (tok->astParent() && Token::Match(tok->astParent()->previous(), "if|while|for ("))) {
733 ValueFlow::Value value{1};
734 if (known)
735 value.setKnown();
736 setTokenValue(tok, std::move(value), settings);
737 }
738 }
739}
740
741static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings)
742{

Callers 1

setValuesMethod · 0.85

Calls 12

isNonZeroFunction · 0.85
getOtherOperandFunction · 0.85
astIsBoolFunction · 0.85
setTokenValueFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
variableMethod · 0.80
isKnownMethod · 0.80
isArrayMethod · 0.80
astParentMethod · 0.80
hasKnownIntValueMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected