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

Function isZeroBoundCond

lib/astutils.cpp:1812–1838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1810}
1811
1812static bool isZeroBoundCond(const Token * const cond, bool reverse)
1813{
1814 if (cond == nullptr || !cond->isBinaryOp())
1815 return false;
1816
1817 const Token* op = reverse ? cond->astOperand1() : cond->astOperand2();
1818 if (!op->hasKnownIntValue())
1819 return true;
1820
1821 // Assume unsigned
1822 const bool isZero = op->getKnownIntValue() == 0;
1823 std::string cmp = cond->str();
1824 if (reverse) {
1825 if (cmp[0] == '>')
1826 cmp[0] = '<';
1827 else if (cmp[0] == '<')
1828 cmp[0] = '>';
1829 }
1830
1831 if (cmp == "==" || cmp == ">=")
1832 return isZero;
1833 if (cmp == "<=")
1834 return true;
1835 if (cmp == "<")
1836 return !isZero;
1837 return false;
1838}
1839
1840bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const Settings& settings, bool pure, bool followVar, ErrorPath* errors)
1841{

Callers 1

isOppositeCondFunction · 0.85

Calls 6

isBinaryOpMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
getKnownIntValueMethod · 0.80
hasKnownIntValueMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected