From: Radoslaw Zarzynski Date: Sat, 15 Apr 2017 17:22:03 +0000 (+0200) Subject: rgw: refactor buf_to_hex and improve its const-correctness. X-Git-Tag: v12.1.0~155^2~55 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=33f013b83520c696b59d12afddf6c593fedf5993;p=ceph.git rgw: refactor buf_to_hex and improve its const-correctness. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index a5745fc33fe7..6bce961986a8 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -2062,18 +2062,21 @@ inline ostream& operator<<(ostream& out, const rgw_obj &o) { return out << o.bucket.name << ":" << o.get_oid(); } -static inline void buf_to_hex(const unsigned char *buf, int len, char *str) +static inline void buf_to_hex(const unsigned char* const buf, + const size_t len, + char* const str) { - int i; str[0] = '\0'; - for (i = 0; i < len; i++) { - sprintf(&str[i*2], "%02x", (int)buf[i]); + for (size_t i = 0; i < len; i++) { + ::sprintf(&str[i*2], "%02x", static_cast(buf[i])); } } template static inline std::array buf_to_hex(const std::array& buf) { + static_assert(N > 0, "The input array must be at least one element long"); + std::array hex_dest; buf_to_hex(buf.data(), N, hex_dest.data()); return hex_dest;