]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/hobject: fix the handling of non-printable chars when listing hobjects
authorRonen Friedman <rfriedma@redhat.com>
Tue, 6 Jul 2021 15:45:21 +0000 (15:45 +0000)
committerRonen Friedman <rfriedma@redhat.com>
Tue, 6 Jul 2021 15:45:21 +0000 (15:45 +0000)
The 'char >= 127' test was always(*) false.

(*) ostensibly - compiler dependent

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/hobject.cc

index 85d4237dcd58cc49f151ef056cb2e1d2d0c1c829..fe4af49d8e9bcf4e73fc34d2a5bf18267dde85ef 100644 (file)
@@ -211,13 +211,14 @@ void hobject_t::generate_test_instances(list<hobject_t*>& o)
 static void append_out_escaped(const string &in, string *out)
 {
   for (string::const_iterator i = in.begin(); i != in.end(); ++i) {
-    if (*i == '%' || *i == ':' || *i == '/' || *i < 32 || *i >= 127) {
+    int k = (int)(unsigned char)(*i);
+    if (k == '%' || k == ':' || k == '/' || k < 32 || k >= 127) {
       out->push_back('%');
       char buf[3];
-      snprintf(buf, sizeof(buf), "%02x", (int)(unsigned char)*i);
+      snprintf(buf, sizeof(buf), "%02x", (int)(unsigned char)k);
       out->append(buf);
     } else {
-      out->push_back(*i);
+      out->push_back(k);
     }
   }
 }