From: Jonathan Roelofs Date: Wed, 12 Feb 2014 06:37:27 +0000 (+0000) Subject: Fix r201205's use-after-free bug caught by sanitizer bot X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a60a522fced577e26041a4885acba6b71a435c91;p=clang Fix r201205's use-after-free bug caught by sanitizer bot git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201209 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Multilib.cpp b/lib/Driver/Multilib.cpp index 6d68517e83..746d01bfb2 100644 --- a/lib/Driver/Multilib.cpp +++ b/lib/Driver/Multilib.cpp @@ -31,16 +31,14 @@ using namespace clang; using namespace llvm::opt; static void normalizePathSegment(std::string &Segment) { - StringRef SRS(Segment); - if (SRS.empty() || SRS == "/." || SRS == "/" || SRS == ".") { - SRS = ""; + if (Segment.empty() || Segment == "/." || Segment == "/" || Segment == ".") { + Segment = ""; } else { - if (SRS.back() == '/') - SRS = SRS.drop_back(); - if (SRS.front() != '/') - SRS = ("/" + SRS).str(); + if (StringRef(Segment).back() == '/') + Segment.erase(Segment.begin() + Segment.size() - 1); + if (StringRef(Segment).front() != '/') + Segment = "/" + Segment; } - Segment = SRS; } Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,