CheckOther:checkNegativeBitwiseShift: Fix FP when shift is protected by ?:

This commit is contained in:
Daniel Marjamäki 2015-01-05 10:01:04 +01:00
parent 1ef1143609
commit fb685f096a
2 changed files with 14 additions and 0 deletions

View File

@ -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)

View File

@ -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() {