From: Adam C. Emerson Date: Wed, 28 Sep 2022 21:45:29 +0000 (-0400) Subject: rgw: Prefer ssize or safe comparison to casts X-Git-Tag: v18.1.0~1071^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=94706f0de5c308cd0198846d8e2ae29e494d66c8;p=ceph.git rgw: Prefer ssize or safe comparison to casts Signed-off-by: Adam C. Emerson --- diff --git a/src/rgw/cls_fifo_legacy.cc b/src/rgw/cls_fifo_legacy.cc index d164a0e40952..23b39b9fa5f0 100644 --- a/src/rgw/cls_fifo_legacy.cc +++ b/src/rgw/cls_fifo_legacy.cc @@ -1406,7 +1406,7 @@ int FIFO::push(const DoutPrefixProvider *dpp, const std::vector& data_ canceled = false; retries = 0; batch_len = 0; - if (static_cast(r) == batch.size()) { + if (r == ssize(batch)) { batch.clear(); } else { batch.erase(batch.begin(), batch.begin() + r); diff --git a/src/rgw/rgw_keystone.h b/src/rgw/rgw_keystone.h index eb4657d4477f..4177c4319311 100644 --- a/src/rgw/rgw_keystone.h +++ b/src/rgw/rgw_keystone.h @@ -4,8 +4,10 @@ #ifndef CEPH_RGW_KEYSTONE_H #define CEPH_RGW_KEYSTONE_H -#include +#include #include +#include +#include #include @@ -14,7 +16,6 @@ #include "common/ceph_mutex.h" #include "global/global_init.h" -#include 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(get_expires()); + return std::cmp_greater_equal(now, get_expires()); } int parse(const DoutPrefixProvider *dpp, CephContext* cct, const std::string& token_str, diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 74c2d5ea8c33..51a6a44e36bf 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -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(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(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(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(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; diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 2e4115aa9d11..6ae2fa7efd95 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -2012,7 +2012,7 @@ bool RGWFormPost::is_non_expired() } const utime_t now = ceph_clock_now(); - if (expires_timestamp <= static_cast(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; diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index ba622d915017..9d043d9dbd83 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -149,7 +149,7 @@ static void get_bucket_index_objects(const string& bucket_oid_base, bucket_objects[i] = buf; } } else { - if (static_cast(shard_id) > num_shards) { + if (std::cmp_greater(shard_id, num_shards)) { return; } else { if (gen_id) {