[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)
commit25daca787a23096622ce9a756f921dd6c12c2b5c
tree96dbd0b29334891a17661c1a02137b5cbc1c964f
parenta05d8be1a2048529fd63aca98acc609f25890c74
[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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243927 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/SmallVector.h