From a565d333dc0a2fe5eaa2159155a9c765838ea0cf Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 24 Feb 2016 17:12:19 +0100 Subject: [PATCH] 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 --- src/test/bufferlist.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()); } } -- 2.47.3