]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: fixed garbage output from test LibRBD.TestIOPP 3182/head
authorJason Dillaman <dillaman@redhat.com>
Mon, 15 Dec 2014 17:37:05 +0000 (12:37 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 15 Dec 2014 17:44:44 +0000 (12:44 -0500)
buffer::list::c_str does not actually provide a C-style, NULL
terminated string.  As a result, its use for console output
resulted in stray garbage characters being printed.

Fixes: #9405
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librbd/test_librbd.cc

index 919de2af7448ec6a2ff7386b0e3237557f1777ef..1a43e7c132a0cf5486ef0d444e22bd0de6819701 100644 (file)
@@ -908,9 +908,14 @@ void read_test_data(librbd::Image& image, const char *expected, off_t off, size_
   ceph::bufferlist bl;
   read = image.read(off + total_read, len, bl);
   ASSERT_TRUE(read >= 0);
+  std::string bl_str(bl.c_str(), read);
+
   printf("read: %u\n", (unsigned int) read);
-  printf("read: %s\nexpected: %s\n", bl.c_str(), expected);
-  ASSERT_EQ(0, memcmp(bl.c_str(), expected, expected_len));
+  int result = memcmp(bl_str.c_str(), expected, expected_len);
+  if (result != 0) {
+    printf("read: %s\nexpected: %s\n", bl_str.c_str(), expected);
+    ASSERT_EQ(0, result);
+  }
   *passed = true;
 }