]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Prefer ssize or safe comparison to casts
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 28 Sep 2022 21:45:29 +0000 (17:45 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 30 Sep 2022 18:51:01 +0000 (14:51 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/cls_fifo_legacy.cc
src/rgw/rgw_keystone.h
src/rgw/rgw_quota.cc
src/rgw/rgw_rest_swift.cc
src/rgw/services/svc_bi_rados.cc

index d164a0e409520f28720c283a2ab49a5e22a9eb31..23b39b9fa5f0da36bf771f0bf333e0353b8fe68e 100644 (file)
@@ -1406,7 +1406,7 @@ int FIFO::push(const DoutPrefixProvider *dpp, const std::vector<cb::list>& data_
     canceled = false;
     retries = 0;
     batch_len = 0;
-    if (static_cast<unsigned>(r) == batch.size()) {
+    if (r == ssize(batch)) {
       batch.clear();
     } else  {
       batch.erase(batch.begin(), batch.begin() + r);
index eb4657d4477f5dc4a7c7d3e5bd8867990dfea3a5..4177c4319311cbe1c6e41edd623adf8b2a4be60e 100644 (file)
@@ -4,8 +4,10 @@
 #ifndef CEPH_RGW_KEYSTONE_H
 #define CEPH_RGW_KEYSTONE_H
 
-#include <type_traits>
+#include <atomic>
 #include <string_view>
+#include <type_traits>
+#include <utility>
 
 #include <boost/optional.hpp>
 
@@ -14,7 +16,6 @@
 #include "common/ceph_mutex.h"
 #include "global/global_init.h"
 
-#include <atomic>
 
 bool rgw_is_pki_token(const std::string& token);
 void rgw_get_token_id(const std::string& token, std::string& token_id);
@@ -197,7 +198,7 @@ public:
   bool has_role(const std::string& r) const;
   bool expired() const {
     const uint64_t now = ceph_clock_now().sec();
-    return now >= static_cast<uint64_t>(get_expires());
+    return std::cmp_greater_equal(now, get_expires());
   }
   int parse(const DoutPrefixProvider *dpp, CephContext* cct,
             const std::string& token_str,
index 74c2d5ea8c33ab55ca44b41f7f47e4ba4b172818..51a6a44e36bfe5f823ee2d4409ee5002291cfe4a 100644 (file)
@@ -783,7 +783,7 @@ bool RGWQuotaInfoDefApplier::is_size_exceeded(const DoutPrefixProvider *dpp,
   const uint64_t cur_size = stats.size_rounded;
   const uint64_t new_size = rgw_rounded_objsize(size);
 
-  if (cur_size + new_size > static_cast<uint64_t>(qinfo.max_size)) {
+  if (std::cmp_greater(cur_size + new_size, qinfo.max_size)) {
     ldpp_dout(dpp, 10) << "quota exceeded: stats.size_rounded=" << stats.size_rounded
              << " size=" << new_size << " "
              << entity << "_quota.max_size=" << qinfo.max_size << dendl;
@@ -804,7 +804,7 @@ bool RGWQuotaInfoDefApplier::is_num_objs_exceeded(const DoutPrefixProvider *dpp,
     return false;
   }
 
-  if (stats.num_objects + num_objs > static_cast<uint64_t>(qinfo.max_objects)) {
+  if (std::cmp_greater(stats.num_objects + num_objs, qinfo.max_objects)) {
     ldpp_dout(dpp, 10) << "quota exceeded: stats.num_objects=" << stats.num_objects
              << " " << entity << "_quota.max_objects=" << qinfo.max_objects
              << dendl;
@@ -827,7 +827,7 @@ bool RGWQuotaInfoRawApplier::is_size_exceeded(const DoutPrefixProvider *dpp,
 
   const uint64_t cur_size = stats.size;
 
-  if (cur_size + size > static_cast<uint64_t>(qinfo.max_size)) {
+  if (std::cmp_greater(cur_size + size, qinfo.max_size)) {
     ldpp_dout(dpp, 10) << "quota exceeded: stats.size=" << stats.size
              << " size=" << size << " "
              << entity << "_quota.max_size=" << qinfo.max_size << dendl;
@@ -848,7 +848,7 @@ bool RGWQuotaInfoRawApplier::is_num_objs_exceeded(const DoutPrefixProvider *dpp,
     return false;
   }
 
-  if (stats.num_objects + num_objs > static_cast<uint64_t>(qinfo.max_objects)) {
+  if (std::cmp_greater(stats.num_objects + num_objs, qinfo.max_objects)) {
     ldpp_dout(dpp, 10) << "quota exceeded: stats.num_objects=" << stats.num_objects
              << " " << entity << "_quota.max_objects=" << qinfo.max_objects
              << dendl;
index 2e4115aa9d1196710b0b8ba285cac5f679d21674..6ae2fa7efd9518fab3401d92c03410add6b0d5d5 100644 (file)
@@ -2012,7 +2012,7 @@ bool RGWFormPost::is_non_expired()
   }
 
   const utime_t now = ceph_clock_now();
-  if (expires_timestamp <= static_cast<uint64_t>(now.sec())) {
+  if (std::cmp_less_equal(expires_timestamp, now.sec())) {
     ldpp_dout(this, 5) << "FormPost form expired: "
             << expires_timestamp << " <= " << now.sec() << dendl;
     return false;
index ba622d915017c6df30c4e8366b70b93b34397114..9d043d9dbd8365b59d8b303a3b50e247600c1b24 100644 (file)
@@ -149,7 +149,7 @@ static void get_bucket_index_objects(const string& bucket_oid_base,
         bucket_objects[i] = buf;
       }
     } else {
-      if (static_cast<uint32_t>(shard_id) > num_shards) {
+      if (std::cmp_greater(shard_id, num_shards)) {
         return;
       } else {
         if (gen_id) {