Fix crash comparing empty file against nonempty file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19782 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index 7ae476b..99db439 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -93,7 +93,8 @@
// with a number. Because of this, if needed, we pad the file so that it starts
// and ends with a null character.
static void PadFileIfNeeded(char *&FileStart, char *&FileEnd, char *&FP) {
- if (isNumberChar(FileStart[0]) || isNumberChar(FileEnd[-1])) {
+ if (FileStart-FileEnd < 2 ||
+ isNumberChar(FileStart[0]) || isNumberChar(FileEnd[-1])) {
unsigned FileLen = FileEnd-FileStart;
char *NewFile = new char[FileLen+2];
NewFile[0] = 0; // Add null padding