Skip to content

Commit ffc0c57

Browse files
Fix crashes on nullptr (danmar#4575)
1 parent 0d29934 commit ffc0c57

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ void CheckClass::assignAllVarsVisibleFromScope(std::vector<Usage>& usageList, co
697697
for (const Type::BaseInfo& i : scope->definedType->derivedFrom) {
698698
const Type *derivedFrom = i.type;
699699

700-
assignAllVarsVisibleFromScope(usageList, derivedFrom->classScope);
700+
if (derivedFrom)
701+
assignAllVarsVisibleFromScope(usageList, derivedFrom->classScope);
701702
}
702703
}
703704

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7634,6 +7634,8 @@ void Tokenizer::findGarbageCode() const
76347634
syntaxError(tok2, "Unexpected token '" + tok2->str() + "'");
76357635
}
76367636
}
7637+
if (Token::Match(tok, "enum : %num%| {"))
7638+
syntaxError(tok->tokAt(2), "Unexpected token '" + tok->strAt(2) + "'");
76377639
}
76387640

76397641
// Keywords in global scope

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ static bool iscpp11init_impl(const Token * const tok)
656656
if (!Token::Match(colonTok->tokAt(-1), "%name%|%num% :"))
657657
return false;
658658
const Token* caseTok = colonTok->tokAt(-2);
659-
while (Token::Match(caseTok->tokAt(-1), "::|%name%"))
659+
while (caseTok && Token::Match(caseTok->tokAt(-1), "::|%name%"))
660660
caseTok = caseTok->tokAt(-1);
661661
return Token::simpleMatch(caseTok, "case");
662662
};

test/testconstructors.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,14 @@ class TestConstructors : public TestFixture {
14401440
"[test.cpp:9]: (warning) Member variable 'B::ca' is not assigned a value in 'B::operator='.\n",
14411441
errout.str());
14421442

1443+
check("class C : B {\n"
1444+
" virtual C& operator=(C& c);\n"
1445+
"};\n"
1446+
"class D : public C {\n"
1447+
" virtual C& operator=(C& c) { return C::operator=(c); };\n"
1448+
"};\n");
1449+
ASSERT_EQUALS("", errout.str());
1450+
14431451
}
14441452

14451453
void initvar_derived_pod_struct_with_union() {

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6759,6 +6759,9 @@ class TestTokenizer : public TestFixture {
67596759

67606760
// #9445 - typeof is not a keyword in C
67616761
ASSERT_NO_THROW(tokenizeAndStringify("void foo() { char *typeof, *value; }", false, Settings::Native, "test.c"));
6762+
6763+
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : { };"), InternalError, "syntax error: Unexpected token '{'");
6764+
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'");
67626765
}
67636766

67646767

0 commit comments

Comments
 (0)