]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
integer being interpreted as a character code when assigning to a string 59489/head
authorSuyash Dongre <suyashd999@gmail.com>
Wed, 28 Aug 2024 19:11:53 +0000 (00:41 +0530)
committerSuyash Dongre <suyashd999@gmail.com>
Sat, 31 Aug 2024 20:44:34 +0000 (02:14 +0530)
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 <suyashd999@gmail.com>
src/cls/rgw/cls_rgw.cc

index 27a484dd51e91a634652315d4f4a01f0f4a9e708..53fca60e884b1377350712ee024ed3f617fa7e37 100644 (file)
@@ -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<char>(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<char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(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