[UB] Fix a nasty place where we would pass null pointers to memcpy.
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Aug 2015 00:44:07 +0000 (00:44 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Aug 2015 00:44:07 +0000 (00:44 +0000)
commit630423e3797639336875edce07b4210dd2cf33a1
tree5c22f898287d7011425aa1855767baaa860c362c
parentb0ae36f0d1417136f1d38e69ee6504decbef8049
[UB] Fix a nasty place where we would pass null pointers to memcpy.

This happens to work, but is not guaranteed to work. Indeed, most memcpy
interfaces in Linux-land annotate these arguments as nonnull, and GCC
and LLVM both can and do optimized based upon that. When they do so,
they might legitimately have miscompiled code calling this routine with
two valid iterators, 'nullptr' and 'nullptr'. There was even code doing
precisely this because StringRef().begin() and StringRef().end() both
produce null pointers.

This was found by UBSan.

llvm-svn: 243927
llvm/include/llvm/ADT/SmallVector.h