From: Suyash Dongre Date: Wed, 28 Aug 2024 19:11:53 +0000 (+0530) Subject: integer being interpreted as a character code when assigning to a string X-Git-Tag: v20.0.0~1140^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=bfbcb3c7f64a94dd1294d2a9fbe808a9856a1237;p=ceph.git integer being interpreted as a character code when assigning to a string clang-tidy original warning: `src/cls/rgw/cls_rgw.cc: warning: an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility [bugprone-string-integer-assignment] key = BI_PREFIX_CHAR; ^ /home/suyash/ceph/src/cls/rgw/cls_rgw.cc:51:24: note: expanded from macro 'BI_PREFIX_CHAR' #define BI_PREFIX_CHAR 0x80` **On the following lines we are getting the warning:** 1. 138 2. 319 3. 342 4. 2875 5. 2966 6. 3294 7. 3304 8. 3307 9. 3418 10. 3421 Signed-off-by: Suyash Dongre --- diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index 27a484dd51e91..53fca60e884b1 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -48,7 +48,7 @@ CLS_NAME(rgw) // of a special bucket-index entry for the first byte. Note: although // it has no impact, the 2nd, 3rd, or 4th byte of a UTF-8 character // may be 0x80. -#define BI_PREFIX_CHAR 0x80 +constexpr unsigned char BI_PREFIX_CHAR = 0x80; #define BI_BUCKET_OBJS_INDEX 0 #define BI_BUCKET_LOG_INDEX 1 @@ -67,11 +67,11 @@ static std::string bucket_index_prefixes[] = { "", /* special handling for the o // this string is greater than all ascii plain entries and less than // all special entries -static const std::string BI_PREFIX_BEGIN = string(1, BI_PREFIX_CHAR); +static const std::string BI_PREFIX_BEGIN = string(1, static_cast(BI_PREFIX_CHAR)); // this string is greater than all special entries and less than all // non-ascii plain entries -static const std::string BI_PREFIX_END = string(1, BI_PREFIX_CHAR) + +static const std::string BI_PREFIX_END = string(1, static_cast(BI_PREFIX_CHAR)) + bucket_index_prefixes[BI_BUCKET_LAST_INDEX]; /* Returns whether parameter is not a key for a special entry. Empty @@ -80,7 +80,7 @@ static const std::string BI_PREFIX_END = string(1, BI_PREFIX_CHAR) + * using appropriately. */ static bool bi_is_plain_entry(const std::string& s) { - return (s.empty() || (unsigned char)s[0] != BI_PREFIX_CHAR); + return (s.empty() || static_cast(s[0]) != BI_PREFIX_CHAR); } static int bi_entry_type(const string& s) @@ -209,7 +209,7 @@ static int get_obj_vals(cls_method_context_t hctx, } auto last_element = pkeys->crbegin(); - if ((unsigned char)last_element->first[0] < BI_PREFIX_CHAR) { + if (static_cast(last_element->first[0]) < BI_PREFIX_CHAR) { /* if the first character of the last entry is less than the * prefix then all entries must preceed the "ugly namespace" and * we're done @@ -218,7 +218,7 @@ static int get_obj_vals(cls_method_context_t hctx, } auto first_element = pkeys->cbegin(); - if ((unsigned char)first_element->first[0] > BI_PREFIX_CHAR) { + if (static_cast(first_element->first[0]) > BI_PREFIX_CHAR) { /* if the first character of the first entry is after the "ugly * namespace" then all entries must follow the "ugly namespace" * then all entries do and we're done