#7769 segmentation fault at setTokenValue() on invalid code.

This commit is contained in:
Alexander Mai 2016-11-06 14:20:58 +01:00
parent 87b08fd405
commit ee11f0974a
2 changed files with 8 additions and 0 deletions

View File

@ -314,6 +314,8 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
setTokenValue(parent, condvalue, settings);
} else {
const Token *op = cond ? tok->astOperand1() : tok->astOperand2();
if (!op) // #7769 segmentation fault at setTokenValue()
return;
const std::list<ValueFlow::Value> &values = op->values;
if (std::find(values.begin(), values.end(), value) != values.end())
setTokenValue(parent, value, settings);

View File

@ -233,6 +233,7 @@ private:
TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageCode184); // #7699
TEST_CASE(garbageCode185); // #7769
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -1529,6 +1530,11 @@ private:
"}");
}
void garbageCode185() { // #7769
// that check failed to reproduce the segfault but got added anyway...
checkCode("!2 : #h2 ?:", false);
}
};
REGISTER_TEST(TestGarbage)