Fixed #7112 (crash: CheckBufferOverrun::checkGlobalAndLocalVariable (invalid code))

This commit is contained in:
Daniel Marjamäki 2015-11-08 14:21:12 +01:00
parent 37dbebb093
commit fc564d779e
2 changed files with 6 additions and 1 deletions

View File

@ -1066,7 +1066,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
{
// check string literals
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "%str% [")) {
if (Token::Match(tok, "%str% [") && tok->next()->astOperand2()) {
const std::size_t strLen = Token::getStrLength(tok);
const ValueFlow::Value *value = tok->next()->astOperand2()->getMaxValue(false);
if (value && value->intvalue > strLen)

View File

@ -202,6 +202,7 @@ private:
TEST_CASE(garbageCode151); // #4175
TEST_CASE(garbageCode152); // travis after 9c7271a5
TEST_CASE(garbageCode153);
TEST_CASE(garbageCode154); // #7112
TEST_CASE(garbageValueFlow);
@ -1218,6 +1219,10 @@ private:
ASSERT_THROW(checkCode("enum { X = << { X } } { X X } enum { X = << { ( X ) } } { } X */"), InternalError);
}
void garbageCode154() {
checkCode("\"abc\"[];");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"