From 503fb485cf3d8bfa5989f7f0a3b4a8e988251bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 30 Jul 2015 13:48:51 +0200 Subject: [PATCH] Removed hardcoding of functions from checkZeroDivision --- lib/checkother.cpp | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c907e9cb0..ae7dddc96 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1797,28 +1797,20 @@ void CheckOther::checkZeroDivision() const bool printInconclusive = _settings->inconclusive; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") && - MathLib::isInt(tok->strAt(4)) && - MathLib::toLongNumber(tok->strAt(4)) == 0L) { - if (tok->str() == "div") { - if (tok->strAt(-1) == ".") - continue; - if (tok->variable() || tok->function()) - continue; - } - zerodivError(tok,false); - } else if (Token::Match(tok, "[/%]") && tok->astOperand2() && !astIsFloat(tok,false)) { - // Value flow.. - const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL); - if (value) { - if (!printInconclusive && value->inconclusive) - continue; - if (value->condition == nullptr) - zerodivError(tok, value->inconclusive); - else if (printWarnings) - zerodivcondError(value->condition,tok,value->inconclusive); - } - } + if (!Token::Match(tok, "[/%]") || !tok->astOperand2()) + continue; + if (astIsFloat(tok,false)) + continue; + // Value flow.. + const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL); + if (!value) + continue; + if (!printInconclusive && value->inconclusive) + continue; + if (value->condition == nullptr) + zerodivError(tok, value->inconclusive); + else if (printWarnings) + zerodivcondError(value->condition,tok,value->inconclusive); } }