]> granicus.if.org Git - clang/commitdiff
Fix r201205's use-after-free bug caught by sanitizer bot
authorJonathan Roelofs <jonathan@codesourcery.com>
Wed, 12 Feb 2014 06:37:27 +0000 (06:37 +0000)
committerJonathan Roelofs <jonathan@codesourcery.com>
Wed, 12 Feb 2014 06:37:27 +0000 (06:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201209 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Multilib.cpp

index 6d68517e83f38fb1f9f8e5a56406614db4714dfc..746d01bfb2411b0ca2079d6f7c303b4d55d61fb4 100644 (file)
@@ -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,