forked from OSchip/llvm-project
clang-format: Fix use-heap-after-free bug.
Discovered by the awesome test case and ASAN. llvm-svn: 226678
This commit is contained in:
parent
17c57ecf4a
commit
fd725c060b
|
@ -59,11 +59,8 @@ public:
|
||||||
I->Tok->Previous = Current;
|
I->Tok->Previous = Current;
|
||||||
Current = Current->Next;
|
Current = Current->Next;
|
||||||
Current->Children.clear();
|
Current->Children.clear();
|
||||||
for (SmallVectorImpl<UnwrappedLine>::const_iterator
|
for (const auto& Child : Node.Children) {
|
||||||
I = Node.Children.begin(),
|
Children.push_back(new AnnotatedLine(Child));
|
||||||
E = Node.Children.end();
|
|
||||||
I != E; ++I) {
|
|
||||||
Children.push_back(new AnnotatedLine(*I));
|
|
||||||
Current->Children.push_back(Children.back());
|
Current->Children.push_back(Children.back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +72,11 @@ public:
|
||||||
for (unsigned i = 0, e = Children.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Children.size(); i != e; ++i) {
|
||||||
delete Children[i];
|
delete Children[i];
|
||||||
}
|
}
|
||||||
|
FormatToken *Current = First;
|
||||||
|
while (Current) {
|
||||||
|
Current->Children.clear();
|
||||||
|
Current = Current->Next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FormatToken *First;
|
FormatToken *First;
|
||||||
|
|
|
@ -2610,6 +2610,8 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
|
||||||
getLLVMStyleWithColumns(28));
|
getLLVMStyleWithColumns(28));
|
||||||
verifyFormat("#d, = };");
|
verifyFormat("#d, = };");
|
||||||
verifyFormat("#if \"a");
|
verifyFormat("#if \"a");
|
||||||
|
|
||||||
|
verifyNoCrash("#if a\na(\n#else\n#endif\n{a");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
|
TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
|
||||||
|
|
Loading…
Reference in New Issue