From 33f013b83520c696b59d12afddf6c593fedf5993 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Sat, 15 Apr 2017 19:22:03 +0200 Subject: [PATCH] rgw: refactor buf_to_hex and improve its const-correctness. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_common.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index a5745fc33fe..6bce961986a 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; -- 2.47.3