Skip to content

Commit 0eb54ba

Browse files
Fix #13578 Crash in setParentExprId() (danmar#7255)
1 parent caa3b75 commit 0eb54ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ namespace {
16091609
typeEndToken = tok->astParent()->link();
16101610
}
16111611
std::string type;
1612-
for (const Token* t = typeStartToken; t != typeEndToken; t = t->next()) {
1612+
for (const Token* t = typeStartToken; precedes(t, typeEndToken); t = t->next()) {
16131613
type += " " + t->str();
16141614
}
16151615
key.parentOp += type;

test/testvarid.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class TestVarID : public TestFixture {
253253
TEST_CASE(exprid11);
254254
TEST_CASE(exprid12);
255255
TEST_CASE(exprid13);
256+
TEST_CASE(exprid14);
256257

257258
TEST_CASE(structuredBindings);
258259
}
@@ -4359,6 +4360,19 @@ class TestVarID : public TestFixture {
43594360
ASSERT_EQUALS(exp, tokenizeExpr(code));
43604361
}
43614362

4363+
void exprid14()
4364+
{
4365+
const Settings s = settingsBuilder(settings).library("std.cfg").build();
4366+
4367+
const char code[] = "int f(double a, double b, double c) {\n" // #13578
4368+
" return static_cast<int>(std::ceil((std::min)(a, (std::min)(b, c))));\n"
4369+
"}\n";
4370+
const char* exp = "1: int f ( double a@1 , double b@2 , double c@3 ) {\n"
4371+
"2: return static_cast < int > ( std :: ceil ( ( std :: min ) ( a@1 , ( std :: min ) ( b@2 , c@3 ) ) ) ) ;\n"
4372+
"3: }\n";
4373+
ASSERT_EQUALS(exp, tokenize(code, dinit(TokenizeOptions, $.s = &s))); // don't crash
4374+
}
4375+
43624376
void structuredBindings() {
43634377
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
43644378
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",

0 commit comments

Comments
 (0)