From: Chandler Carruth Date: Tue, 4 Aug 2015 00:53:01 +0000 (+0000) Subject: [UB] Fix another place where we would pass a null pointer to memcpy. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d86ea348636c2368029034561d5c2e3f0c8a2f75;p=oota-llvm.git [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243932 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 8721c73b95b..9d038560bf9 100644 --- a/include/llvm/ADT/StringMap.h +++ b/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; }