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

Method testIfNonZeroExpressionIsPositive

lib/checkother.cpp:3259–3279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3257}
3258
3259bool CheckOtherImpl::testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr)
3260{
3261 if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2())
3262 return false;
3263
3264 const ValueFlow::Value *v1 = tok->astOperand1()->getValue(0);
3265 const ValueFlow::Value *v2 = tok->astOperand2()->getValue(0);
3266
3267 if (Token::simpleMatch(tok, ">=") && v2 && v2->isKnown()) {
3268 zeroValue = v2;
3269 nonZeroExpr = tok->astOperand1();
3270 } else if (Token::simpleMatch(tok, "<=") && v1 && v1->isKnown()) {
3271 zeroValue = v1;
3272 nonZeroExpr = tok->astOperand2();
3273 } else {
3274 return false;
3275 }
3276
3277 const ValueType* vt = nonZeroExpr->valueType();
3278 return vt && (vt->pointer || vt->sign == ValueType::UNSIGNED);
3279}
3280
3281void CheckOtherImpl::unsignedLessThanZeroError(const Token *tok, const ValueFlow::Value * v, const std::string &varname)
3282{

Callers

nothing calls this directly

Calls 5

astOperand1Method · 0.80
astOperand2Method · 0.80
isKnownMethod · 0.80
simpleMatchFunction · 0.70
getValueMethod · 0.45

Tested by

no test coverage detected