Protect memcpy calls against undefined behaviour
[folly.git] / folly / io / test / IOBufTest.cpp
index 7f7e55c5346fffa9245ed6d61c68cb118c046243..85b9dcb36cad690ce84339f14a94607b5596bdf5 100644 (file)
@@ -1325,3 +1325,16 @@ TEST(IOBuf, Managed) {
   writableStr(*buf2)[0] = 'x';
   EXPECT_EQ("jelloxorldhelloxorld", toString(*buf1));
 }
+
+TEST(IOBuf, CoalesceEmptyBuffers) {
+  auto b1 = IOBuf::takeOwnership(nullptr, 0);
+  auto b2 = fromStr("hello");
+  auto b3 = IOBuf::takeOwnership(nullptr, 0);
+
+  b2->appendChain(std::move(b3));
+  b1->appendChain(std::move(b2));
+
+  auto br = b1->coalesce();
+
+  EXPECT_TRUE(ByteRange(StringPiece("hello")) == br);
+}