Fixed #5472 (sizeof not handled as operator with respect to null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2014-04-29 20:09:11 +02:00
parent fc24d491cc
commit b5e023a46c
2 changed files with 14 additions and 0 deletions

View File

@ -409,6 +409,14 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
break;
}
if (Token::Match(tok2->previous(), "sizeof|.")) {
const Token *prev = tok2->previous();
while (Token::Match(prev,"%var%|.") && prev->str() != "sizeof")
prev = prev->previous();
if (Token::Match(prev,"sizeof"))
continue;
}
// assigned by subfunction?
bool inconclusive = false;
if (bailoutFunctionPar(tok2,val2.condition ? val2 : val, settings, &inconclusive)) {

View File

@ -374,6 +374,12 @@ private:
" if (x==63){}\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 2U, 63));
code = "void f(int *x) {\n"
" char a[sizeof x.y];\n"
" if (x==0){}\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 2U, 0));
}
void valueFlowBeforeConditionIfElse() { // bailout: if/else/etc