From: Erwan Velu Date: Wed, 24 Feb 2016 16:12:19 +0000 (+0100) Subject: test/bufferlist: Avoid false-positive tests X-Git-Tag: v10.1.0~151^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a565d333dc0a2fe5eaa2159155a9c765838ea0cf;p=ceph.git test/bufferlist: Avoid false-positive tests The current code is using the length of ptr to determine if the string is correct. As 'ptr' is a copy of the original 'str', it sounds safer to compare against the original string size of the consider the actual size of the string : if 'ptr' is shorter than 'str', the actual code will PASS while 'ptr' is broken. This patch offer to use the same testing logic as per "ptr(const ptr& p, unsigned o, unsigned l)" test by using a memcmp against the original string length. Signed-off-by: Erwan Velu --- diff --git a/src/test/bufferlist.cc b/src/test/bufferlist.cc index a6120fd06141..8be65f60896d 100644 --- a/src/test/bufferlist.cc +++ b/src/test/bufferlist.cc @@ -478,7 +478,7 @@ TEST(BufferPtr, constructors) { bufferptr ptr(std::move(original)); EXPECT_TRUE(ptr.have_raw()); EXPECT_FALSE(original.have_raw()); - EXPECT_EQ(str.compare(0, str.size(), ptr.c_str(), ptr.length()), 0); + EXPECT_EQ(0, ::memcmp(str.c_str(), ptr.c_str(), len)); EXPECT_EQ(1, ptr.raw_nref()); } }