Fix crash comparing empty file against nonempty file.
authorChris Lattner <sabre@nondot.org>
Sun, 23 Jan 2005 06:02:40 +0000 (06:02 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 23 Jan 2005 06:02:40 +0000 (06:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19782 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/FileUtilities.cpp

index 7ae476b5975d104cb6e15a7d35687d493e2d221a..99db439d327a2717b4ca0566e26beb86510f0390 100644 (file)
@@ -93,7 +93,8 @@ static bool CompareNumbers(char *&F1P, char *&F2P, char *F1End, char *F2End,
 // 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