]> granicus.if.org Git - clang/commitdiff
[clang-format] Fix MatchingOpeningBlockLineIndex computation
authorKrasimir Georgiev <krasimir@google.com>
Thu, 18 May 2017 15:16:24 +0000 (15:16 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Thu, 18 May 2017 15:16:24 +0000 (15:16 +0000)
Summary:
Computed line index must be relative to the current 'parent' node, and
thus use CurrentLines instead of Lines.

Without this, a child line's MatchingOpeningBlockLineIndex is out of
range of the parent's list of line, which can cause crash or unexpected
behavior if this field is used in childs.

Contributed by @Typz!

Reviewers: krasimir, djasper

Reviewed By: krasimir

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D32524

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303353 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp

index 31c66ffb00a12e0a520653a82c01d5159e88bc7c..e2762cd42c4f674cb461c72818411cc890f3ae2b 100644 (file)
@@ -429,8 +429,9 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
     parseParens();
 
   addUnwrappedLine();
-  size_t OpeningLineIndex =
-      Lines.empty() ? (UnwrappedLine::kInvalidIndex) : (Lines.size() - 1);
+  size_t OpeningLineIndex = CurrentLines->empty()
+                                ? (UnwrappedLine::kInvalidIndex)
+                                : (CurrentLines->size() - 1);
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                           MustBeDeclaration);