Commit bc02b7a4 authored by Lucian Grijincu's avatar Lucian Grijincu Committed by Facebook Github Bot 8

folly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling...

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
parent 3ce293fa
...@@ -400,7 +400,9 @@ public: ...@@ -400,7 +400,9 @@ public:
} else } else
#endif #endif
{ {
fbstring_detail::pod_copy(data, data + size, small_); if (size != 0) {
fbstring_detail::pod_copy(data, data + size, small_);
}
} }
setSmallSize(size); setSmallSize(size);
} else { } else {
...@@ -1375,7 +1377,9 @@ public: ...@@ -1375,7 +1377,9 @@ public:
Invariant checker(*this); Invariant checker(*this);
// s can alias this, we need to use pod_move. // 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()); fbstring_detail::pod_move(s, s + n, store_.mutable_data());
resize(n); resize(n);
assert(size() == n); assert(size() == n);
...@@ -1736,10 +1740,9 @@ public: ...@@ -1736,10 +1740,9 @@ public:
enforce(pos <= size(), std::__throw_out_of_range, ""); enforce(pos <= size(), std::__throw_out_of_range, "");
procrustes(n, size() - pos); procrustes(n, size() - pos);
fbstring_detail::pod_copy( if (n != 0) {
data() + pos, fbstring_detail::pod_copy(data() + pos, data() + pos + n, s);
data() + pos + n, }
s);
return n; return n;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment