[llvm] r243934 - [UB] Fix yet another use of memcpy with a null pointer argument. I think
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 6:05 PM Chandler Carruth <chandlerc at gmail.com> wrote:
>>
>> Author: chandlerc
>> Date: Mon Aug 3 20:00:56 2015
>> New Revision: 243934
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=243934&view=rev
>> Log:
>> [UB] Fix yet another use of memcpy with a null pointer argument. I think
>> this is the last of them in my build of LLVM. Haven't tried Clang yet.
>>
>> Found via UBSan.
>>
>> Modified:
>> llvm/trunk/lib/Support/MemoryBuffer.cpp
>>
>> Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=243934&r1=243933&r2=243934&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
>> +++ llvm/trunk/lib/Support/MemoryBuffer.cpp Mon Aug 3 20:00:56 2015
>> @@ -57,7 +57,8 @@ void MemoryBuffer::init(const char *BufS
>> /// CopyStringRef - Copies contents of a StringRef into a block of memory
>> and
>> /// null-terminates it.
>> static void CopyStringRef(char *Memory, StringRef Data) {
>> - memcpy(Memory, Data.data(), Data.size());
>> + if (!Data.empty())
>> + memcpy(Memory, Data.data(), Data.size());
>> Memory[Data.size()] = 0; // Null terminate string.
>> }
>>
>>
>>
>> _______________________________________________
>> 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