[llvm] r243934 - [UB] Fix yet another use of memcpy with a null pointer argument. I think
Chandler Carruth
chandlerc at gmail.com
Mon Aug 3 18:17:43 PDT 2015
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150804/25e4a7f0/attachment.html>
More information about the llvm-commits
mailing list