From bc02b7a42d2424af74fa526349d2a531a49c83d3 Mon Sep 17 00:00:00 2001 From: Lucian Grijincu Date: Sat, 14 May 2016 00:38:50 -0700 Subject: [PATCH] folly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling them when size == 0 and (likely) source is nullptr Summary: Also see {D3295811} Differential Revision: D3302564 fbshipit-source-id: 3f2dbf5a6cfa8199682cb4af90aac372d501919a --- folly/FBString.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index b5e9b2f8..4f0d3231 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -400,7 +400,9 @@ public: } else #endif { - fbstring_detail::pod_copy(data, data + size, small_); + if (size != 0) { + fbstring_detail::pod_copy(data, data + size, small_); + } } setSmallSize(size); } else { @@ -1375,7 +1377,9 @@ public: Invariant checker(*this); // s can alias this, we need to use pod_move. - if (size() >= n) { + if (n == 0) { + resize(0); + } else if (size() >= n) { fbstring_detail::pod_move(s, s + n, store_.mutable_data()); resize(n); assert(size() == n); @@ -1736,10 +1740,9 @@ public: enforce(pos <= size(), std::__throw_out_of_range, ""); procrustes(n, size() - pos); - fbstring_detail::pod_copy( - data() + pos, - data() + pos + n, - s); + if (n != 0) { + fbstring_detail::pod_copy(data() + pos, data() + pos + n, s); + } return n; } -- 2.34.1