From 1fb0b1750c5f98551ac7ac35789683ee7cda59a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 7 Jan 2014 19:46:13 +0100 Subject: [PATCH] value flow: Fixed FP in ?: --- lib/valueflow.cpp | 5 +++++ test/testvalueflow.cpp | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a8226f302..b8b2f11cc 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -62,6 +62,11 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog } else { continue; } + if (Token::Match(tok->astParent(), "[?:]")) { + if (settings->debugwarnings) + bailout(tokenlist, errorLogger, tok, "variable " + var->nameToken()->str() + " stopping on " + tok->astParent()->str()); + continue; + } } else if (Token::Match(tok->previous(), "if|while ( %var% %oror%|&&|)") || Token::Match(tok, "%oror%|&& %var% %oror%|&&|)")) { varid = tok->next()->varId(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 3dc6333a4..d04587dee 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -82,6 +82,12 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); + // bailout: ?: + bailout("void f(int x) {\n" + " y = ((x<0) ? x : ((x==2)?3:4));\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on :\n", errout.str()); + // bailout: if/else/etc bailout("void f(int x) {\n" " if (x != 123) { b = x; }\n"