From 54aede9086639a0de24637fa800474f516890fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Jun 2014 19:30:46 +0200 Subject: [PATCH] Fixed #5941 (ValueFlow: Wrong value in subfunction under ?) --- lib/valueflow.cpp | 4 ++-- test/testsimplifytokens.cpp | 2 +- test/testvalueflow.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ce32cb5ad..c540372ca 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1212,9 +1212,9 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger, if (Token::Match(tok2, "%varid% !!=", varid2)) { for (std::list::const_iterator val = argvalues.begin(); val != argvalues.end(); ++val) setTokenValue(const_cast(tok2), *val); - } else if (tok2->str() == "{") { + } else if (tok2->str() == "{" || tok2->str() == "?") { if (settings->debugwarnings) - bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str()); + bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str() + ", at '" + tok2->str() + "'"); break; } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index ec8a45ac9..4a82dffe1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4418,7 +4418,7 @@ private: "[test.cpp:20] -> [test.cpp:1]: (style, inconclusive) The function parameter 'A' hides a typedef with the same name.\n" "[test.cpp:21] -> [test.cpp:1]: (style, inconclusive) The variable 'A' hides a typedef with the same name.\n" "[test.cpp:24] -> [test.cpp:1]: (style, inconclusive) The typedef 'A' hides a typedef with the same name.\n" - "[test.cpp:24]: (debug) ValueFlow bailout: parameter a\n", errout.str()); + "[test.cpp:24]: (debug) ValueFlow bailout: parameter a, at '{'\n", errout.str()); } void simplifyTypedef36() { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 42bd4427e..af2ff8027 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -892,6 +892,14 @@ private: code = "void f1(int x) { a=(abc)x; }\n" "void f2(int y) { f1(123); }\n"; ASSERT_EQUALS(true, testValueOfX(code, 1U, 123)); + + code = "void f1(int x) {\n" + " x ?\n" + " 1024 / x :\n" + " 0; }\n" + "void f2() { f1(0); }"; + ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); + ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); } };