[llvm] r243932 - [UB] Fix another place where we would pass a null pointer to memcpy.
Chandler Carruth
chandlerc at gmail.com
Mon Aug 3 18:17:27 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 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150804/55bfc0fb/attachment.html>
More information about the llvm-commits
mailing list