From 4815e3c4c5725f80cbff9014b1226d109f47587b Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Tue, 29 Apr 2014 20:16:50 +0200 Subject: [PATCH] Fix some segmentation faults seen while reducing #5743 (sorry, no test cases supplied) --- lib/tokenize.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 128c82ea4..904216979 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -103,7 +103,7 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last, std::stack 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 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