summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-06-02 13:52:16 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-06-02 13:52:16 +0000
commit5b31205211395ca094999e173ecc326dd49b0729 (patch)
tree1bb7b6317a180faf3a85c9df82a700c04b57b2ea /libcxx
parent44a129c533ac895293e98a6924a5a4ac18330e67 (diff)
downloadbcm5719-llvm-5b31205211395ca094999e173ecc326dd49b0729.tar.gz
bcm5719-llvm-5b31205211395ca094999e173ecc326dd49b0729.zip
Fix some places where we could call memmove(null,xxx,0) - which is UB
llvm-svn: 238831
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/algorithm20
1 files changed, 14 insertions, 6 deletions
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76f59f24024..459071f0984 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -1763,7 +1763,8 @@ typename enable_if
__copy(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
- _VSTD::memmove(__result, __first, __n * sizeof(_Up));
+ if (__n > 0)
+ _VSTD::memmove(__result, __first, __n * sizeof(_Up));
return __result + __n;
}
@@ -1798,8 +1799,11 @@ typename enable_if
__copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
- __result -= __n;
- _VSTD::memmove(__result, __first, __n * sizeof(_Up));
+ if (__n > 0)
+ {
+ __result -= __n;
+ _VSTD::memmove(__result, __first, __n * sizeof(_Up));
+ }
return __result;
}
@@ -1896,7 +1900,8 @@ typename enable_if
__move(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
- _VSTD::memmove(__result, __first, __n * sizeof(_Up));
+ if (__n > 0)
+ _VSTD::memmove(__result, __first, __n * sizeof(_Up));
return __result + __n;
}
@@ -1931,8 +1936,11 @@ typename enable_if
__move_backward(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
- __result -= __n;
- _VSTD::memmove(__result, __first, __n * sizeof(_Up));
+ if (__n > 0)
+ {
+ __result -= __n;
+ _VSTD::memmove(__result, __first, __n * sizeof(_Up));
+ }
return __result;
}
OpenPOWER on IntegriCloud