This commit is contained in:
orbitcowboy 2014-04-23 01:24:01 +02:00
commit e48550d8d7
3 changed files with 17 additions and 3 deletions

View File

@ -103,7 +103,7 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last,
std::stack<Token *> links;
Token *tok2 = dest;
unsigned int linenrs = dest->linenr();
unsigned int commonFileIndex = dest->fileIndex();
const unsigned int commonFileIndex = dest->fileIndex();
for (const Token *tok = first; tok != last->next(); tok = tok->next()) {
tok2->insertToken(tok->str());
tok2 = tok2->next();
@ -2640,7 +2640,7 @@ void Tokenizer::setVarId()
std::map<std::string, unsigned int> varlist;
const Token* tokStart = Token::findsimplematch(tok, "{");
if (tokStart) {
for (const Token *tok2 = tokStart->next(); tok2 != tokStart->link(); tok2 = tok2->next()) {
for (const Token *tok2 = tokStart->next(); tok2 && tok2 != tokStart->link(); tok2 = tok2->next()) {
// skip parentheses..
if (tok2->link()) {
if (tok2->str() == "{")
@ -5234,7 +5234,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
continue;
} else if (tok->str() == "(") {
if (isCPP()) {
for (Token * tok2 = tok; tok2 != tok->link(); tok2 = tok2->next()) {
for (Token * tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {
if (Token::Match(tok2, "[(,] [")) {
// lambda function at tok2->next()
// find start of lambda body

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