diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index bf09904b2..8a9416415 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4450,6 +4450,8 @@ static std::vector getConditions(const Token* tok, const char* op) return false; if (tok2->hasKnownIntValue()) return false; + if (Token::Match(tok2, "%var%") && !astIsBool(tok2)) + return false; return true; }); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f7153a86a..a986b5f38 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6173,6 +6173,18 @@ private: " ASSERT(!(t4 < t5) && t4 <= t5);\n" "}"; valueOfTok(code, "<="); + + code = "void f() {\n" + " unsigned short Xoff = 10;\n" + " unsigned short Nx = 0;\n" + " int last;\n" + " do {\n" + " last = readData(0);\n" + " if (last && (last - Xoff < Nx))\n" + " Nx = last - Xoff;\n" + " } while (last > 0);\n" + "}\n"; + valueOfTok(code, "last"); } void valueFlowHang() {