#6127 crash on patch(?)-".c" file. Avoid segfault.

This commit is contained in:
Alexander Mai 2014-09-04 21:27:33 +02:00
parent 65f599bd9e
commit 5a96413220
2 changed files with 8 additions and 4 deletions

View File

@ -124,8 +124,8 @@ static bool conditionIsTrue(const Token *condition, const std::map<unsigned int,
if (!condition)
return false;
if (condition->str() == "||") {
bool result1 = conditionIsTrue(condition->astOperand1(), programMemory);
bool result2 = result1 ? true : conditionIsTrue(condition->astOperand2(), programMemory);
const bool result1 = conditionIsTrue(condition->astOperand1(), programMemory);
const bool result2 = result1 ? true : conditionIsTrue(condition->astOperand2(), programMemory);
return result2;
}
std::map<unsigned int, MathLib::bigint> progmem(programMemory);
@ -1440,7 +1440,7 @@ static void valueFlowForLoop(TokenList *tokenlist, ErrorLogger *errorLogger, con
continue;
Token * const bodyStart = tok->linkAt(1)->next();
if (!bodyStart->link() || bodyStart->str() != "{")
if (!bodyStart || !bodyStart->link() || bodyStart->str() != "{")
continue;
unsigned int varid(0);

View File

@ -86,7 +86,7 @@ private:
TEST_CASE(garbageCode7);
TEST_CASE(garbageCode8); // #5511
TEST_CASE(garbageCode9); // #5604
TEST_CASE(garbageCode10); // #6127
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
TEST_CASE(foreach); // #3690
@ -1115,6 +1115,10 @@ private:
ASSERT_THROW(tokenizeAndStringify("enum { e = { } } ( ) { { enum { } } } { e } ", true), InternalError);
}
void garbageCode10() { // #6127
tokenizeAndStringify("for( rl=reslist; rl!=NULL; rl=rl->next )", /*simplify=*/true);
}
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
ASSERT_EQUALS("\"test.cpp\"", tokenizeAndStringify("__FILE__"));
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));