]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/rgw: Replace VLAs/`snprintf` with `fmt::format`
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 26 Mar 2026 02:40:16 +0000 (22:40 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 26 Mar 2026 04:07:21 +0000 (00:07 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/cls/rgw/cls_rgw.cc
src/test/cls_rgw/test_cls_rgw.cc

index fbe5525a40cb9b84547936509f482d25078d68ec..755d690dd9a6867d5171df5641a6aa1a5c081ae5 100644 (file)
@@ -3,20 +3,23 @@
 
 #include "include/types.h"
 
-#include <errno.h>
+#include <cerrno>
+#include <map>
+#include <string>
+#include <vector>
+#include <utility>
+
+#include <fmt/format.h>
 
 #include <boost/algorithm/string.hpp>
 
 #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 <boost/lexical_cast.hpp>
 
 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)
index 953581c904e2313267afb6c66ab979ed503de5fe..639ec51a5e5616613e37944c7cb02f367097a4fe 100644 (file)
@@ -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 <errno.h>
+#include <cerrno>
 #include <string>
 #include <vector>
 #include <map>
-#include <set>
+
+#include <fmt/format.h>
 
 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,