[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:02:02 PDT 2018
    
    
  
hokein updated this revision to Diff 161467.
hokein added a comment.
Correct the fix.
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
@@ -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.161467.patch
Type: text/x-patch
Size: 429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180820/83fb1895/attachment.bin>
    
    
More information about the cfe-commits
mailing list