[llvm] r243932 - [UB] Fix another place where we would pass a null pointer to memcpy.
Chandler Carruth
chandlerc at gmail.com
Mon Aug 3 17:53:02 PDT 2015
Author: chandlerc
Date: Mon Aug 3 19:53:01 2015
New Revision: 243932
URL: http://llvm.org/viewvc/llvm-project?rev=243932&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/ADT/StringMap.h
Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=243932&r1=243931&r2=243932&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Mon Aug 3 19:53:01 2015
@@ -158,7 +158,8 @@ public:
// Copy the string information.
char *StrBuffer = const_cast<char*>(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;
}
More information about the llvm-commits
mailing list