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

Method isIntArgValid

lib/library.cpp:1116–1136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114}
1115
1116bool Library::isIntArgValid(const Token *ftok, int argnr, const MathLib::bigint argvalue, const Settings& settings) const
1117{
1118 const ArgumentChecks *ac = getarg(ftok, argnr);
1119 if (!ac || ac->valid.empty())
1120 return true;
1121 if (ac->valid.find('.') != std::string::npos)
1122 return isFloatArgValid(ftok, argnr, static_cast<double>(argvalue), settings);
1123 TokenList tokenList(settings, ftok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
1124 gettokenlistfromvalid(ac->valid, tokenList);
1125 for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
1126 if (tok->isNumber() && argvalue == MathLib::toBigNumber(tok))
1127 return true;
1128 if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toBigNumber(tok) && argvalue <= MathLib::toBigNumber(tok->tokAt(2)))
1129 return true;
1130 if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toBigNumber(tok))
1131 return true;
1132 if ((!tok->previous() || tok->strAt(-1) == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toBigNumber(tok->tokAt(1)))
1133 return true;
1134 }
1135 return false;
1136}
1137
1138bool Library::isFloatArgValid(const Token *ftok, int argnr, double argvalue, const Settings& settings) const
1139{

Callers 3

getInvalidValueMethod · 0.80
invalidFunctionUsageMethod · 0.80
function_arg_validMethod · 0.80

Calls 6

gettokenlistfromvalidFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
emptyMethod · 0.45
findMethod · 0.45
tokAtMethod · 0.45

Tested by 1

function_arg_validMethod · 0.64