Refactorization: use MathLib::isNullValue in CheckOther::checkMemsetInvalid2ndParam(); Fixed it to support also float literals like "0.f"

This commit is contained in:
Philipp Kloke 2014-04-11 12:00:33 +02:00
parent cf30fab413
commit 1fafc7f4dc
2 changed files with 8 additions and 9 deletions

View File

@ -1744,8 +1744,8 @@ void CheckOther::checkMemsetInvalid2ndParam()
if (!secondParamTok)
continue;
// Second parameter is zero float literal, i.e. 0.0f
if (Token::Match(secondParamTok,"%num% ,") && secondParamTok->str().find_first_not_of("0.f") == std::string::npos)
// Second parameter is zero literal, i.e. 0.0f
if (Token::Match(secondParamTok, "%num% ,") && MathLib::isNullValue(secondParamTok->str()))
continue;
const Token *top = secondParamTok;

View File

@ -600,15 +600,14 @@ bool MathLib::isLessEqual(const std::string &first, const std::string &second)
bool MathLib::isNullValue(const std::string &str)
{
return (str == "-0" || str == "0" || str == "+0"
|| str == "-0.0" || str == "0.0" || str == "+0.0"
|| str == "-0." || str == "+0."
|| str == "-0E-00" || str == "-0E+00" || str == "+0E+00" || str == "+0E-00"
|| str == "-0e-00" || str == "-0e+00" || str == "+0e+00" || str == "+0e-00"
|| str == "-0E-0");
for (size_t i = 0; i < str.size(); i++) {
if (std::isdigit(static_cast<unsigned char>(str[i])) && str[i] != '0') // May not contain digits other than 0
return false;
}
return !str.empty() && (std::isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-' || str[0] == '+'); // Has to be a number
}
bool MathLib::isOctalDigit(char c)
{
return (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7');
return (c >= '0' && c <= '7');
}