diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 70db245c3..ff2c0746f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 518bed03d..bb0fb1147 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -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(str[i])) && str[i] != '0') // May not contain digits other than 0 + return false; + } + return !str.empty() && (std::isdigit(static_cast(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'); }