[llvm] 90966da - Support: Avoid SmallVector::assign with a range from to-be-replaced vector in Windows GetExecutableName

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 17:56:42 PST 2020


Author: Duncan P. N. Exon Smith
Date: 2020-11-18T17:55:49-08:00
New Revision: 90966daac3dd633b9621426e6621a706807d7c0d

URL: https://github.com/llvm/llvm-project/commit/90966daac3dd633b9621426e6621a706807d7c0d
DIFF: https://github.com/llvm/llvm-project/commit/90966daac3dd633b9621426e6621a706807d7c0d.diff

LOG: Support: Avoid SmallVector::assign with a range from to-be-replaced vector in Windows GetExecutableName

This code wasn't valid, and 5abf76fbe37380874a88cc9aa02164800e4e10f3
started asserting. This is a speculative fix since I don't have a
Windows machine handy.

Added: 
    

Modified: 
    llvm/lib/Support/Windows/Process.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index 8064d4e17b29..910d2395d277 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -228,7 +228,8 @@ static std::error_code GetExecutableName(SmallVectorImpl<char> &Filename) {
   if (EC)
     return EC;
 
-  StringRef Base = sys::path::filename(Filename.data());
+  // Make a copy of the filename since assign makes the StringRef invalid.
+  std::string Base = sys::path::filename(Filename.data()).str();
   Filename.assign(Base.begin(), Base.end());
   return std::error_code();
 }


        


More information about the llvm-commits mailing list