From 7f7274ce7f3243bd71588c7a75a142c39e5c7e34 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 18 Aug 2010 00:11:25 +0000 Subject: [PATCH] Don't pass in a null pointer to std::string's ctor, an empty string 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 33756f605f0..9962bb2b188 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -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 -- 2.11.0