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 | 9748310eabd7928129cf6a8e2faa7890e6b61bdf (patch) | |
| tree | 9d1f7159a8255d22e9939ee80851ccb09a2d660a /llvm/lib | |
| parent | ee8c0051d3d54b31e428e38483d6051013086806 (diff) | |
| download | bcm5719-llvm-9748310eabd7928129cf6a8e2faa7890e6b61bdf.tar.gz bcm5719-llvm-9748310eabd7928129cf6a8e2faa7890e6b61bdf.zip | |
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.
llvm-svn: 116925
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/System/Win32/Path.inc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/System/Win32/Path.inc b/llvm/lib/System/Win32/Path.inc index 4a6dbd3ddf2..2dbf13e8ccb 100644 --- a/llvm/lib/System/Win32/Path.inc +++ b/llvm/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) { |

