[llvm] r243932 - [UB] Fix another place where we would pass a null pointer to memcpy.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 09:04:00 PDT 2015


Merged in r244224.

On Mon, Aug 3, 2015 at 6:17 PM, Chandler Carruth <chandlerc at gmail.com> wrote:
> Should probably pull this into the release as it fixes something that could
> miscompile in the future with a new host compiler.
>
>
> On Mon, Aug 3, 2015 at 5:56 PM Chandler Carruth <chandlerc at gmail.com> wrote:
>>
>> 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;
>>    }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list