[PATCH] D50966: Fix an undefined behavior when storing an empty StringRef.
Haojian Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 20 05:21:30 PDT 2018
hokein created this revision.
hokein added a reviewer: ioeric.
Herald added a subscriber: llvm-commits.
Passing a nullptr to memcpy is UB.
Repository:
rL LLVM
https://reviews.llvm.org/D50966
Files:
lib/Support/StringSaver.cpp
Index: lib/Support/StringSaver.cpp
===================================================================
--- lib/Support/StringSaver.cpp
+++ lib/Support/StringSaver.cpp
@@ -12,6 +12,8 @@
using namespace llvm;
StringRef StringSaver::save(StringRef S) {
+ if (S.empty())
+ return StringRef();
char *P = Alloc.Allocate<char>(S.size() + 1);
memcpy(P, S.data(), S.size());
P[S.size()] = '\0';
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50966.161463.patch
Type: text/x-patch
Size: 403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180820/8064aeba/attachment.bin>
More information about the llvm-commits
mailing list