From fb685f096a4cb3585215c87af5b38ca066527331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 5 Jan 2015 10:01:04 +0100 Subject: [PATCH] CheckOther:checkNegativeBitwiseShift: Fix FP when shift is protected by ?: --- lib/checkother.cpp | 11 +++++++++++ test/testother.cpp | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 015f76c98..0a6da02c6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2663,6 +2663,17 @@ void CheckOther::checkNegativeBitwiseShift() continue; } + // bailout if operation is protected by ?: + bool ternary = false; + for (const Token *parent = tok; parent; parent = parent->astParent()) { + if (Token::Match(parent, "?|:")) { + ternary = true; + break; + } + } + if (ternary) + continue; + // Get negative rhs value. preferably a value which doesn't have 'condition'. const ValueFlow::Value *value = tok->astOperand2()->getValueLE(-1LL, _settings); if (value) diff --git a/test/testother.cpp b/test/testother.cpp index db1febaa8..01630ff2e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5490,6 +5490,9 @@ private: " std::cout << 3 << -1 ;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("x = y ? z << $-1 : 0;\n"); + ASSERT_EQUALS("", errout.str()); } void incompleteArrayFill() {