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

Function valueFlowBitAnd

lib/valueflow.cpp:853–882  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

851}
852
853static void valueFlowBitAnd(TokenList& tokenlist, const Settings& settings)
854{
855 for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
856 if (tok->str() != "&")
857 continue;
858
859 if (tok->hasKnownValue())
860 continue;
861
862 if (!tok->astOperand1() || !tok->astOperand2())
863 continue;
864
865 MathLib::bigint number;
866 if (MathLib::isInt(tok->astOperand1()->str()))
867 number = MathLib::toBigNumber(tok->astOperand1());
868 else if (MathLib::isInt(tok->astOperand2()->str()))
869 number = MathLib::toBigNumber(tok->astOperand2());
870 else
871 continue;
872
873 int bit = 0;
874 while (bit <= (MathLib::bigint_bits - 2) && ((static_cast<MathLib::bigint>(1) << bit) < number))
875 ++bit;
876
877 if ((static_cast<MathLib::bigint>(1) << bit) == number) {
878 setTokenValue(tok, ValueFlow::Value(0), settings);
879 setTokenValue(tok, ValueFlow::Value(number), settings);
880 }
881 }
882}
883
884static void valueFlowSameExpressions(TokenList& tokenlist, const Settings& settings)
885{

Callers 1

setValuesMethod · 0.85

Calls 8

setTokenValueFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
hasKnownValueMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
ValueClass · 0.70
strMethod · 0.45

Tested by

no test coverage detected