Fixed #5376 (false positive: zerodivcond (style) Either the condition 'B>0' is useless or there is division by zero)
This commit is contained in:
parent
84c5f47eb1
commit
7ff7bc1c2e
|
@ -294,7 +294,15 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
val2.varId = varid;
|
||||
}
|
||||
}
|
||||
|
||||
if (Token::Match(tok,"<|>")) {
|
||||
if (num!=0)
|
||||
continue;
|
||||
bool isunsigned = false;
|
||||
for (const Token* type = var->typeStartToken(); type && type->varId() == 0U; type = type->next())
|
||||
isunsigned |= type->isUnsigned();
|
||||
if (!isunsigned)
|
||||
continue;
|
||||
}
|
||||
for (Token *tok2 = tok->previous(); ; tok2 = tok2->previous()) {
|
||||
if (!tok2) {
|
||||
if (settings->debugwarnings) {
|
||||
|
|
|
@ -157,6 +157,24 @@ private:
|
|||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 1));
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
|
||||
|
||||
code = "void f(unsigned int x) {\n"
|
||||
" int a = x;\n"
|
||||
" if (x > 0) {}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
|
||||
|
||||
code = "void f(unsigned int x) {\n"
|
||||
" int a = x;\n"
|
||||
" if (x > 1) {}\n" // not zero => don't consider > condition
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 2U, 1));
|
||||
|
||||
code = "void f(int x) {\n" // not unsigned => don't consider > condition
|
||||
" int a = x;\n"
|
||||
" if (x > 0) {}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 2U, 0));
|
||||
|
||||
code = "void f(int *x) {\n"
|
||||
" *x = 100;\n"
|
||||
" if (x) {}\n"
|
||||
|
|
Loading…
Reference in New Issue