mmap of a zero length file returns null on some platforms, so hack around it.
authorBrian Gaeke <gaeke@uiuc.edu>
Fri, 23 Apr 2004 17:38:17 +0000 (17:38 +0000)
committerBrian Gaeke <gaeke@uiuc.edu>
Fri, 23 Apr 2004 17:38:17 +0000 (17:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13121 91177308-0d34-0410-b5e6-96231b3b80d8

utils/fpcmp/fpcmp.cpp

index 6f8298e5c78bebbae2329f737dc9ca5b84df5f1f..7e472d474f67fcdaf0daf0cd3e382caf067e6a3a 100644 (file)
@@ -50,6 +50,12 @@ static void OpenFile(const std::string &Filename, unsigned &Len, char* &BufPtr){
     std::cerr << "Error: cannot open file '" << Filename << "'\n";
     exit(2);
   }
+
+  // If mmap decided that the files were empty, it might have returned a
+  // null pointer. If so, make a new, fake pointer -- it shouldn't matter
+  // what it contains, because Len is 0, and it should never be read.
+  if (BufPtr == 0 && Len == 0)
+    BufPtr = new char[1];
 }
 
 static bool isNumberChar(char C) {