]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
testradospp: zero terminate before printing strs
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 25 Mar 2011 21:45:37 +0000 (14:45 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 25 Mar 2011 21:45:37 +0000 (14:45 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/testradospp.cc

index d1860d2f9448f976bd080f0e49b58e0b3c48f353..1db8f2f7d2cab2497647771597c16c39dc55b677 100644 (file)
@@ -177,7 +177,18 @@ int main(int argc, const char **argv)
   }
 
   int size = io_ctx.read(oid, bl2, 128, 0);
-  cout << "read result=" << bl2.c_str() << std::endl;
+  if (size <= 0) {
+    cout << "failed to read oid " << oid << "." << std::endl;
+    exit(1);
+  }
+  if (size > 4096) {
+    cout << "read too many bytes from oid " << oid << "." << std::endl;
+    exit(1);
+  }
+  char rbuf[size + 1];
+  memcpy(rbuf, bl2.c_str(), size);
+  rbuf[size] = '\0';
+  cout << "read result='" << rbuf << "'" << std::endl;
   cout << "size=" << size << std::endl;
 
   const char *oid2 = "jjj10.rbd";