X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fio%2Ftest%2FIOBufCursorTest.cpp;h=68aa7784b1cb5d6e2231d152f60a7724bb57b959;hp=cfc5109db81dc0efe4b13419b141d45539abc81f;hb=46c5dbce6c04234ae0185d3fadb62556c7e7625b;hpb=2734e379f411f7d9757f9b8d13c020249a6c2dd6 diff --git a/folly/io/test/IOBufCursorTest.cpp b/folly/io/test/IOBufCursorTest.cpp index cfc5109d..68aa7784 100644 --- a/folly/io/test/IOBufCursorTest.cpp +++ b/folly/io/test/IOBufCursorTest.cpp @@ -286,7 +286,6 @@ TEST(IOBuf, pushCursorData) { EXPECT_EQ(1, rcursor2.readBE()); EXPECT_EQ(10, rcursor2.readBE()); EXPECT_EQ(20, rcursor2.readBE()); - } TEST(IOBuf, Gather) { @@ -1115,3 +1114,21 @@ TEST(IOBuf, readConsumesAllInputOnFailure) { EXPECT_THROW(rcursor.read(), std::out_of_range); EXPECT_EQ(0, rcursor.totalLength()); } + +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()); +}