diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-10-20 15:23:58 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-10-20 15:23:58 +0000 |
commit | a9cf7b84435951ab2ce7d4d9629bc4619226264a (patch) | |
tree | 8cec7c8e9cdd3527e3ca185d6a2fe97aa7b949d0 /lib/System/Win32 | |
parent | 7283da51b8860ca9af4cb5ca082f7bcca3894d99 (diff) | |
download | external_llvm-a9cf7b84435951ab2ce7d4d9629bc4619226264a.zip external_llvm-a9cf7b84435951ab2ce7d4d9629bc4619226264a.tar.gz external_llvm-a9cf7b84435951ab2ce7d4d9629bc4619226264a.tar.bz2 |
System-Win32/Path: Fix incorrect assumption in isValid.
A recent commit to clang exposed a bug in the Win32 Path code. This is a
minimal fix for it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116925 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Win32')
-rw-r--r-- | lib/System/Win32/Path.inc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index 4a6dbd3..2dbf13e 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -64,6 +64,13 @@ Path::operator=(StringRef that) { return *this; } +// push_back 0 on create, and pop_back on delete. +struct ScopedNullTerminator { + std::string &str; + ScopedNullTerminator(std::string &s) : str(s) { str.push_back(0); } + ~ScopedNullTerminator() { str.pop_back(); } +}; + bool Path::isValid() const { if (path.empty()) @@ -72,6 +79,8 @@ Path::isValid() const { // If there is a colon, it must be the second character, preceded by a letter // and followed by something. size_t len = path.size(); + // This code assumes that path is null terminated, so make sure it is. + ScopedNullTerminator snt(path); size_t pos = path.rfind(':',len); size_t rootslash = 0; if (pos != std::string::npos) { |