[PATCH] D50966: Fix an undefined behavior when storing an empty StringRef.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 20 06:13:46 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL340170: Fix an undefined behavior when storing an empty StringRef. (authored by hokein, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D50966

Files:
  llvm/trunk/lib/Support/StringSaver.cpp


Index: llvm/trunk/lib/Support/StringSaver.cpp
===================================================================
--- llvm/trunk/lib/Support/StringSaver.cpp
+++ llvm/trunk/lib/Support/StringSaver.cpp
@@ -13,7 +13,8 @@
 
 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());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50966.161469.patch
Type: text/x-patch
Size: 462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180820/cc77f3ee/attachment.bin>


More information about the cfe-commits mailing list