From: Adam C. Emerson Date: Thu, 26 Mar 2026 02:40:16 +0000 (-0400) Subject: cls/rgw: Replace VLAs/`snprintf` with `fmt::format` X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c3a287146b24d72a451740fe617146ac7bb28a66;p=ceph.git cls/rgw: Replace VLAs/`snprintf` with `fmt::format` Signed-off-by: Adam C. Emerson --- diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index fbe5525a40cb..755d690dd9a6 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -3,20 +3,23 @@ #include "include/types.h" -#include +#include +#include +#include +#include +#include + +#include #include #include "objclass/objclass.h" #include "cls/rgw/cls_rgw_ops.h" #include "cls/rgw/cls_rgw_const.h" -#include "common/Clock.h" #include "common/strtol.h" #include "common/escape.h" -#include "common/config_proxy.h" #include "osd/osd_types.h" -#include "include/compat.h" #include using std::pair; @@ -4005,9 +4008,7 @@ static void usage_record_prefix_by_time(uint64_t epoch, string& key) static void usage_record_prefix_by_user_old(const string& user, uint64_t epoch, string& key) { - char buf[user.size() + 32]; - snprintf(buf, sizeof(buf), "%s_%011llu_", user.c_str(), (long long unsigned)epoch); - key = buf; + key = fmt::format("{}_{:011}_", user, epoch); } static void usage_record_prefix_by_user(const string& user, uint64_t epoch, string& key) @@ -4022,16 +4023,12 @@ static void usage_record_prefix_by_user(const string& user, uint64_t epoch, stri static void usage_record_name_by_time(uint64_t epoch, const string& user, const string& bucket, string& key) { - char buf[32 + user.size() + bucket.size()]; - snprintf(buf, sizeof(buf), "%011llu_%s_%s", (long long unsigned)epoch, user.c_str(), bucket.c_str()); - key = buf; + key = fmt::format("{:011}_{}_{}", epoch, user, bucket); } static void usage_record_name_by_user_old(const string& user, uint64_t epoch, const string& bucket, string& key) { - char buf[32 + user.size() + bucket.size()]; - snprintf(buf, sizeof(buf), "%s_%011llu_%s", user.c_str(), (long long unsigned)epoch, bucket.c_str()); - key = buf; + key = fmt::format("{}_{:011}_{}", user, epoch, bucket); } static void usage_record_name_by_user(const string& user, uint64_t epoch, const string& bucket, string& key) diff --git a/src/test/cls_rgw/test_cls_rgw.cc b/src/test/cls_rgw/test_cls_rgw.cc index 953581c904e2..639ec51a5e56 100644 --- a/src/test/cls_rgw/test_cls_rgw.cc +++ b/src/test/cls_rgw/test_cls_rgw.cc @@ -1,20 +1,19 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- // vim: ts=8 sw=2 sts=2 expandtab -#include "include/types.h" #include "cls/rgw/cls_rgw_client.h" #include "cls/rgw/cls_rgw_ops.h" #include "gtest/gtest.h" #include "test/librados/test_cxx.h" -#include "global/global_context.h" -#include "common/ceph_context.h" +#include "include/common_fwd.h" -#include +#include #include #include #include -#include + +#include using namespace std; using namespace librados; @@ -1028,16 +1027,12 @@ auto gen_usage_log_info(std::string payer, std::string bucket, int total_usage_e // Copied from cls_rgw.cc in order to populate usage logs with old keys static void usage_record_name_by_time(uint64_t epoch, const std::string& user, const std::string& bucket, std::string& key) { - char buf[32 + user.size() + bucket.size()]; - snprintf(buf, sizeof(buf), "%011llu_%s_%s", (long long unsigned)epoch, user.c_str(), bucket.c_str()); - key = buf; + key = fmt::format("{:011}_{}_{}", epoch, user, bucket); } static void usage_record_name_by_user_old(const std::string& user, uint64_t epoch, const std::string& bucket, std::string& key) { - char buf[32 + user.size() + bucket.size()]; - snprintf(buf, sizeof(buf), "%s_%011llu_%s", user.c_str(), (long long unsigned)epoch, bucket.c_str()); - key = buf; + key = fmt::format("{}_{:011}_{}", user, epoch, bucket); } void populate_old_usage_log_info(librados::IoCtx &ioctx,