[llvm] d1587c3 - [llvm] Fix string copy confusion

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 09:38:35 PDT 2022


Author: Nathan Sidwell
Date: 2022-03-28T09:37:36-07:00
New Revision: d1587c38e6baba70b81d02c31641a17e568a9f5c

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

LOG: [llvm] Fix string copy confusion

The microsoft demangler makes copies of the demangled strings, but has
some confusion between StringView representation (sans NUL), and
C-strings (with NUL).  Here we also have a use of strcpy, which
happens to work because the incoming string view happens to have a
trailing NUL.  But a simple memcpy excluding the NUL is sufficient.

Reviewed By: dblaikie, erichkeane

Differential Revision: https://reviews.llvm.org/D122391

Added: 
    

Modified: 
    llvm/lib/Demangle/MicrosoftDemangle.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index d8da3b48e25b9..a009befdb3715 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -245,8 +245,8 @@ demanglePointerCVQualifiers(StringView &MangledName) {
 }
 
 StringView Demangler::copyString(StringView Borrowed) {
-  char *Stable = Arena.allocUnalignedBuffer(Borrowed.size() + 1);
-  std::strcpy(Stable, Borrowed.begin());
+  char *Stable = Arena.allocUnalignedBuffer(Borrowed.size());
+  std::memcpy(Stable, Borrowed.begin(), Borrowed.size());
 
   return {Stable, Borrowed.size()};
 }


        


More information about the llvm-commits mailing list