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;
|
||||
Current = Current->Next;
|
||||
Current->Children.clear();
|
||||
for (SmallVectorImpl<UnwrappedLine>::const_iterator
|
||||
I = Node.Children.begin(),
|
||||
E = Node.Children.end();
|
||||
I != E; ++I) {
|
||||
Children.push_back(new AnnotatedLine(*I));
|
||||
for (const auto& Child : Node.Children) {
|
||||
Children.push_back(new AnnotatedLine(Child));
|
||||
Current->Children.push_back(Children.back());
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +72,11 @@ public:
|
|||
for (unsigned i = 0, e = Children.size(); i != e; ++i) {
|
||||
delete Children[i];
|
||||
}
|
||||
FormatToken *Current = First;
|
||||
while (Current) {
|
||||
Current->Children.clear();
|
||||
Current = Current->Next;
|
||||
}
|
||||
}
|
||||
|
||||
FormatToken *First;
|
||||
|
|
|
@ -2610,6 +2610,8 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
|
|||
getLLVMStyleWithColumns(28));
|
||||
verifyFormat("#d, = };");
|
||||
verifyFormat("#if \"a");
|
||||
|
||||
verifyNoCrash("#if a\na(\n#else\n#endif\n{a");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
|
||||
|
|
Loading…
Reference in New Issue