Make sure getName().data() is always null terminated.
authorDaniel Dunbar <daniel@zuster.org>
Sun, 26 Jul 2009 09:22:02 +0000 (09:22 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 26 Jul 2009 09:22:02 +0000 (09:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77149 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Value.cpp

index fa82bac60e3b1b4716f43877587bfc08ba5ba671..10e62ff1bc3ca715c9729125db60c1e977ee7e5c 100644 (file)
@@ -152,7 +152,10 @@ static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
 }
 
 StringRef Value::getName() const {
-  if (!Name) return StringRef();
+  // Make sure the empty string is still a C string. For historical reasons,
+  // some clients want to call .data() on the result and expect it to be null
+  // terminated.
+  if (!Name) return StringRef("", 0);
   return Name->getKey();
 }