diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-08-31 06:36:33 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-08-31 06:36:33 +0000 |
commit | 1211d43abfd870c969ffb875d646e762a420e666 (patch) | |
tree | b3481c5a0bb7aa3c06644a9e6f072299fbe5fbe9 | |
parent | a805b2ded869d5342397d0c62c3c3848900e5c8f (diff) | |
download | external_llvm-1211d43abfd870c969ffb875d646e762a420e666.zip external_llvm-1211d43abfd870c969ffb875d646e762a420e666.tar.gz external_llvm-1211d43abfd870c969ffb875d646e762a420e666.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112586 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/System/Win32/Path.inc | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index 42e58a4..4a6dbd3 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -722,7 +722,7 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const { 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 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const { if (!ret || nRead != len) return false; - buf[len] = '\0'; - Magic = buf; + Magic = std::string(buf, len); return true; } |