folly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling them...
authorLucian Grijincu <lucian@fb.com>
Sat, 14 May 2016 07:38:50 +0000 (00:38 -0700)
committerFacebook Github Bot 8 <facebook-github-bot-8-bot@fb.com>
Sat, 14 May 2016 07:53:25 +0000 (00:53 -0700)
Summary: Also see {D3295811}

Differential Revision: D3302564

fbshipit-source-id: 3f2dbf5a6cfa8199682cb4af90aac372d501919a

folly/FBString.h

index b5e9b2f822ec344bed31bc40087326060ff5d980..4f0d323158442440e611079e69b0f4d40ab28815 100644 (file)
@@ -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;
   }