+
+TEST(IOBuf, pushEmptyByteRange) {
+ // Test pushing an empty ByteRange. This mainly tests that we do not
+ // trigger UBSAN warnings by calling memcpy() with an null source pointer,
+ // which is undefined behavior even if the length is 0.
+ IOBuf buf{IOBuf::CREATE, 2};
+ ByteRange emptyBytes;
+
+ // Test calling Cursor::push()
+ RWPrivateCursor wcursor(&buf);
+ wcursor.push(emptyBytes);
+ EXPECT_EQ(0, buf.computeChainDataLength());
+
+ // Test calling Appender::push()
+ Appender app(&buf, 16);
+ app.push(emptyBytes);
+ EXPECT_EQ(0, buf.computeChainDataLength());
+}