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

Method isFloatArgValid

lib/library.cpp:1138–1158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1136}
1137
1138bool Library::isFloatArgValid(const Token *ftok, int argnr, double argvalue, const Settings& settings) const
1139{
1140 const ArgumentChecks *ac = getarg(ftok, argnr);
1141 if (!ac || ac->valid.empty())
1142 return true;
1143 TokenList tokenList(settings, ftok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
1144 gettokenlistfromvalid(ac->valid, tokenList);
1145 for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
1146 if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toDoubleNumber(tok) && argvalue <= MathLib::toDoubleNumber(tok->tokAt(2)))
1147 return true;
1148 if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toDoubleNumber(tok))
1149 return true;
1150 if ((!tok->previous() || tok->strAt(-1) == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toDoubleNumber(tok->tokAt(1)))
1151 return true;
1152 if (Token::Match(tok, "%num%") && MathLib::isFloat(tok->str()) && MathLib::isEqual(tok->str(), MathLib::toString(argvalue)))
1153 return true;
1154 if (Token::Match(tok, "! %num%") && MathLib::isFloat(tok->strAt(1)))
1155 return MathLib::isNotEqual(tok->strAt(1), MathLib::toString(argvalue));
1156 }
1157 return false;
1158}
1159
1160std::string Library::getFunctionName(const Token *ftok, bool &error) const
1161{

Callers 2

getInvalidValueMethod · 0.80
function_arg_validMethod · 0.80

Calls 10

gettokenlistfromvalidFunction · 0.85
isFloatFunction · 0.85
isEqualFunction · 0.85
isNotEqualFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
toStringFunction · 0.70
emptyMethod · 0.45
tokAtMethod · 0.45
strMethod · 0.45

Tested by 1

function_arg_validMethod · 0.64