From 13c247b45523ce787390aea806c3345b8038632d Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 4 Aug 2015 00:53:01 +0000 Subject: [PATCH] [UB] Fix another place where we would pass a null pointer to memcpy. This too was found by UBSan. Down to 35 failures for me. llvm-svn: 243932 --- llvm/include/llvm/ADT/StringMap.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h index 8721c73b..9d03856 100644 --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/include/llvm/ADT/StringMap.h @@ -158,7 +158,8 @@ public: // Copy the string information. char *StrBuffer = const_cast(NewItem->getKeyData()); - memcpy(StrBuffer, Key.data(), KeyLength); + if (KeyLength > 0) + memcpy(StrBuffer, Key.data(), KeyLength); StrBuffer[KeyLength] = 0; // Null terminate for convenience of clients. return NewItem; } -- 2.7.4