forked from OSchip/llvm-project
Fix an undefined behavior when storing an empty StringRef.
Summary: Passing a nullptr to memcpy is UB. Reviewers: ioeric Subscribers: llvm-commits, cfe-commits Differential Revision: https://reviews.llvm.org/D50966 llvm-svn: 340170
This commit is contained in:
parent
5b78c9d58d
commit
54829bb3ff
|
@ -13,7 +13,8 @@ using namespace llvm;
|
|||
|
||||
StringRef StringSaver::save(StringRef S) {
|
||||
char *P = Alloc.Allocate<char>(S.size() + 1);
|
||||
memcpy(P, S.data(), S.size());
|
||||
if (!S.empty())
|
||||
memcpy(P, S.data(), S.size());
|
||||
P[S.size()] = '\0';
|
||||
return StringRef(P, S.size());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue