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

Method comparisonNonZeroExpressionLessThanZero

lib/checkother.cpp:3233–3257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3231}
3232
3233bool CheckOtherImpl::comparisonNonZeroExpressionLessThanZero(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr, bool suppress)
3234{
3235 if (!tok->isComparisonOp() || !tok->astOperand1() || !tok->astOperand2())
3236 return false;
3237
3238 const ValueFlow::Value *v1 = tok->astOperand1()->getValue(0);
3239 const ValueFlow::Value *v2 = tok->astOperand2()->getValue(0);
3240
3241 if (Token::Match(tok, "<|<=") && v2 && v2->isKnown()) {
3242 zeroValue = v2;
3243 nonZeroExpr = tok->astOperand1();
3244 } else if (Token::Match(tok, ">|>=") && v1 && v1->isKnown()) {
3245 zeroValue = v1;
3246 nonZeroExpr = tok->astOperand2();
3247 } else {
3248 return false;
3249 }
3250
3251 if (const Variable* var = nonZeroExpr->variable())
3252 if (var->typeStartToken()->isTemplateArg())
3253 return suppress;
3254
3255 const ValueType* vt = nonZeroExpr->valueType();
3256 return vt && (vt->pointer || vt->sign == ValueType::UNSIGNED);
3257}
3258
3259bool CheckOtherImpl::testIfNonZeroExpressionIsPositive(const Token *tok, const ValueFlow::Value *&zeroValue, const Token *&nonZeroExpr)
3260{

Callers

nothing calls this directly

Calls 5

astOperand1Method · 0.80
astOperand2Method · 0.80
isKnownMethod · 0.80
variableMethod · 0.80
getValueMethod · 0.45

Tested by

no test coverage detected