From fe7595cd9db86a43c966676eaf73108f12c0fccb Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 9 Jan 2022 15:43:08 -0600 Subject: [PATCH] Fix 10677: crash during valueFlowInferCondition (#3687) --- lib/valueflow.cpp | 2 ++ test/testvalueflow.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) 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() {