Skip to content

Commit 8adff0a

Browse files
committed
danmar#6712 segmentation fault (invalid code) in CheckExceptionSafety::checkRethrowCopy. Local fix to avoid accessing NULL-token
1 parent 133d8f9 commit 8adff0a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/checkexceptionsafety.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ void CheckExceptionSafety::checkRethrowCopy()
155155
const unsigned int varid = i->classStart->tokAt(-2)->varId();
156156
if (varid) {
157157
for (const Token* tok = i->classStart->next(); tok && tok != i->classEnd; tok = tok->next()) {
158-
if (Token::simpleMatch(tok, "catch (") && tok->next()->link() && tok->next()->link()->next()) // Don't check inner catch - it is handled in another iteration of outer loop.
158+
if (Token::simpleMatch(tok, "catch (") && tok->next()->link() && tok->next()->link()->next()) { // Don't check inner catch - it is handled in another iteration of outer loop.
159159
tok = tok->next()->link()->next()->link();
160-
else if (Token::Match(tok, "throw %varid% ;", varid))
160+
if (!tok)
161+
break;
162+
} else if (Token::Match(tok, "throw %varid% ;", varid))
161163
rethrowCopyError(tok, tok->strAt(1));
162164
}
163165
}

test/testgarbage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class TestGarbage : public TestFixture {
8686
TEST_CASE(garbageCode45); // #6608
8787
TEST_CASE(garbageCode46); // #6705
8888
TEST_CASE(garbageCode47); // #6706
89+
TEST_CASE(garbageCode48); // #6712
8990

9091
TEST_CASE(garbageValueFlow);
9192
TEST_CASE(garbageSymbolDatabase);
@@ -495,6 +496,10 @@ class TestGarbage : public TestFixture {
495496
checkCode(" { { }; }; * new private: B: B;");
496497
}
497498

499+
void garbageCode48() { // #6712
500+
checkCode(" { d\n\" ) d ...\n\" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \"\" } }");
501+
}
502+
498503
void garbageValueFlow() {
499504
// #6089
500505
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"

0 commit comments

Comments
 (0)