clang-format: Fix formatting of empty files (fixes c-index-tests).
llvm-svn: 195638
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 1f3eef4..b5b3797 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1332,8 +1332,9 @@
SourceLocation Start = First.WhitespaceRange.getBegin();
if (!IncludeLeadingNewlines)
Start = Start.getLocWithOffset(First.LastNewlineOffset);
- SourceLocation End = Last.getStartOfNonWhitespace().getLocWithOffset(
- Last.TokenText.size() - 1);
+ SourceLocation End = Last.getStartOfNonWhitespace();
+ if (Last.TokenText.size() > 0)
+ End = End.getLocWithOffset(Last.TokenText.size() - 1);
CharSourceRange Range = CharSourceRange::getCharRange(Start, End);
return affectsCharSourceRange(Range);
}