Don't pass in a null pointer to std::string's ctor, an empty string
authorChris Lattner <sabre@nondot.org>
Wed, 18 Aug 2010 00:11:25 +0000 (00:11 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 18 Aug 2010 00:11:25 +0000 (00:11 +0000)
ref should produce an empty std::string.  This fixes PR7879.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111332 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringRef.h

index 33756f605f01ee3a3acb501a3a3a3ceb400d8834..9962bb2b18888e274f5405f62ac2fa7b4728579c 100644 (file)
@@ -149,7 +149,10 @@ namespace llvm {
     unsigned edit_distance(StringRef Other, bool AllowReplacements = true);
 
     /// str - Get the contents as an std::string.
-    std::string str() const { return std::string(Data, Length); }
+    std::string str() const {
+      if (Data == 0) return "";
+      return std::string(Data, Length);
+    }
 
     /// @}
     /// @name Operator Overloads