Skip to content

Commit

Permalink
[llvm] Fix string copy confusion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
urnathan committed Mar 28, 2022
1 parent 8a1956d commit d1587c3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Demangle/MicrosoftDemangle.cpp
Expand Up @@ -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()};
}
Expand Down

0 comments on commit d1587c3

Please sign in to comment.