[llvm-commits] [llvm] r112586 - /llvm/trunk/lib/System/Win32/Path.inc

Michael J. Spencer bigcheesegs at gmail.com
Mon Aug 30 23:36:33 PDT 2010


Author: mspencer
Date: Tue Aug 31 01:36:33 2010
New Revision: 112586

URL: http://llvm.org/viewvc/llvm-project?rev=112586&view=rev
Log:
System: Fix getMagicNumber on windows.

getMagicNumber was treating the _binary_ data it read in as a
null terminated string. This resulted in the std::string
calculating the length, and causing an assert in other code that
assumed that the length it passed was the same as the length of
the string it would get back.

Modified:
    llvm/trunk/lib/System/Win32/Path.inc

Modified: llvm/trunk/lib/System/Win32/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Path.inc?rev=112586&r1=112585&r2=112586&view=diff
==============================================================================
--- llvm/trunk/lib/System/Win32/Path.inc (original)
+++ llvm/trunk/lib/System/Win32/Path.inc Tue Aug 31 01:36:33 2010
@@ -722,7 +722,7 @@
 
 bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
   assert(len < 1024 && "Request for magic string too long");
-  char* buf = (char*) alloca(1 + len);
+  char* buf = reinterpret_cast<char*>(alloca(len));
 
   HANDLE h = CreateFile(path.c_str(),
                         GENERIC_READ,
@@ -741,8 +741,7 @@
   if (!ret || nRead != len)
     return false;
 
-  buf[len] = '\0';
-  Magic = buf;
+  Magic = std::string(buf, len);
   return true;
 }
 





More information about the llvm-commits mailing list