From c2b4e14d1e1f0f948912936f7a47cd018c2280f9 Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Fri, 14 Aug 2026 11:21:38 -0700 Subject: [PATCH 1/2] Avoid needless copies reported by Coverity Scan Replaces a copy with a move where the source is not used again, and binds a reference instead of copying where a loop variable or local only reads the referent. No behavior change: every move source was checked to be dead after the move, and every reference was checked to outlive its use. Adds to four files that now name std::move but did not include it directly. Verified with a clean build (no new warnings) and the full unit test suite on Fedora, GCC 16.1.1. --- plugins/cachekey/cachekey.cc | 2 +- plugins/cachekey/configs.cc | 2 +- plugins/esi/lib/EsiParser.cc | 7 ++++--- plugins/experimental/access_control/config.cc | 8 ++++---- plugins/experimental/access_control/pattern.cc | 4 ++-- plugins/experimental/jax_fingerprint/ja4h/test.cc | 2 +- plugins/experimental/rate_limit/sni_selector.cc | 2 +- plugins/experimental/rate_limit/txn_limiter.cc | 3 ++- plugins/experimental/stek_share/log_store.cc | 6 +++--- plugins/experimental/stek_share/state_machine.h | 2 +- plugins/experimental/stek_share/state_manager.h | 4 +++- plugins/experimental/stek_share/stek_share.cc | 6 +++--- plugins/header_rewrite/operators.cc | 4 ++-- plugins/origin_server_auth/origin_server_auth.cc | 2 +- plugins/traffic_dump/session_data.cc | 3 ++- plugins/traffic_dump/transaction_data.cc | 2 +- src/api/InkAPI.cc | 4 ++-- src/config/ssl_multicert.cc | 8 ++++---- src/iocore/net/SSLCertLookup.cc | 2 +- src/iocore/net/SSLNetVConnection.cc | 3 ++- src/iocore/net/SSLUtils.cc | 6 +++--- src/iocore/net/UnixNetAccept.cc | 6 +++--- src/proxy/HostStatus.cc | 2 +- src/proxy/http/PreWarmManager.cc | 4 ++-- src/traffic_ctl/CtrlCommands.cc | 2 +- src/traffic_ctl/jsonrpc/ctrl_yaml_codecs.h | 2 +- src/tscore/ArgParser.cc | 4 ++-- src/tscore/Layout.cc | 4 ++-- src/tscore/runroot.cc | 13 +++++++------ src/tsutil/Metrics.cc | 2 +- 30 files changed, 64 insertions(+), 57 deletions(-) diff --git a/plugins/cachekey/cachekey.cc b/plugins/cachekey/cachekey.cc index 81748076899..9d5e04e7eef 100644 --- a/plugins/cachekey/cachekey.cc +++ b/plugins/cachekey/cachekey.cc @@ -518,7 +518,7 @@ captureWholeHeaders(const ConfigHeaders &config, const String &name, const Strin if (config.toBeAdded(name)) { String header; header.append(name).append(":").append(value); - captures.insert(header); + captures.insert(std::move(header)); CacheKeyDebug("adding header '%s: %s'", name.c_str(), value.c_str()); } else { CacheKeyDebug("failed to find header '%s'", name.c_str()); diff --git a/plugins/cachekey/configs.cc b/plugins/cachekey/configs.cc index 1eeebdb64a2..d08d7a20948 100644 --- a/plugins/cachekey/configs.cc +++ b/plugins/cachekey/configs.cc @@ -587,7 +587,7 @@ Configs::setKeyType(const char *arg) StringVector types; ::commaSeparateString(types, arg); - for (auto type : types) { + for (const auto &type : types) { if (9 == type.length() && 0 == strncasecmp(type.c_str(), "cache_key", 9)) { _keyTypes.insert(CacheKeyKeyType::CACHE_KEY); CacheKeyDebug("setting cache key"); diff --git a/plugins/esi/lib/EsiParser.cc b/plugins/esi/lib/EsiParser.cc index 44d5a0bb9de..92a05fdb176 100644 --- a/plugins/esi/lib/EsiParser.cc +++ b/plugins/esi/lib/EsiParser.cc @@ -27,6 +27,7 @@ #include #include +#include using std::string; using namespace EsiLib; @@ -256,7 +257,7 @@ EsiParser::_processSimpleContentTag(DocNode::TYPE node_type, const char *data, i TSError("[%s] Could not parse simple content of [%s] node", __FUNCTION__, DocNode::type_names_[node_type]); return false; } - node_list.push_back(new_node); + node_list.push_back(std::move(new_node)); return true; } @@ -541,7 +542,7 @@ EsiParser::_processTryTag(const string &data, size_t curr_pos, size_t end_pos, D TSError("[%s] try block must contain one each of attempt and except nodes", __FUNCTION__); return false; } - node_list.push_back(try_node); + node_list.push_back(std::move(try_node)); Dbg(dbg_ctl, "[%s] Added try node successfully", __FUNCTION__); return true; } @@ -586,7 +587,7 @@ EsiParser::_processChooseTag(const string &data, size_t curr_pos, size_t end_pos } ++iter; } - node_list.push_back(choose_node); + node_list.push_back(std::move(choose_node)); return true; } diff --git a/plugins/experimental/access_control/config.cc b/plugins/experimental/access_control/config.cc index 0a2f435ab21..30b65077b30 100644 --- a/plugins/experimental/access_control/config.cc +++ b/plugins/experimental/access_control/config.cc @@ -100,10 +100,10 @@ loadLine(StringMap &map, const String &line) std::getline(ss, value, '='); trim(key); trim(value); - map[key] = value; + map[key] = std::move(value); #ifdef ACCESS_CONTROL_LOG_SECRETS - AccessControlDebug("Adding secrets[%s]='%s'", key.c_str(), value.c_str()); + AccessControlDebug("Adding secrets[%s]='%s'", key.c_str(), map[key].c_str()); #endif } @@ -116,10 +116,10 @@ loadLine(StringVector &vector, const String &line) { String trimmedLine(line); trim(trimmedLine); - vector.push_back(trimmedLine); + vector.push_back(std::move(trimmedLine)); #ifdef ACCESS_CONTROL_LOG_SECRETS - AccessControlDebug("Adding secrets[%d]='%s'", (int)(vector.size() - 1), trimmedLine.c_str()); + AccessControlDebug("Adding secrets[%d]='%s'", (int)(vector.size() - 1), vector.back().c_str()); #endif } diff --git a/plugins/experimental/access_control/pattern.cc b/plugins/experimental/access_control/pattern.cc index a1153e6a2de..0a424d8207a 100644 --- a/plugins/experimental/access_control/pattern.cc +++ b/plugins/experimental/access_control/pattern.cc @@ -163,7 +163,7 @@ Pattern::process(const String &subject, StringVector &result) /* Replacement pattern was provided in the configuration - capture and replace. */ String element; if (replace(subject, element)) { - result.push_back(element); + result.push_back(std::move(element)); } else { return false; } @@ -242,7 +242,7 @@ Pattern::capture(const String &subject, StringVector &result) String dst(match_view.data(), match_view.size()); AccessControlDebug("capturing '%s' %d", dst.c_str(), i); - result.push_back(dst); + result.push_back(std::move(dst)); } return true; diff --git a/plugins/experimental/jax_fingerprint/ja4h/test.cc b/plugins/experimental/jax_fingerprint/ja4h/test.cc index 3d1abb50224..9ebf6dfb3a5 100644 --- a/plugins/experimental/jax_fingerprint/ja4h/test.cc +++ b/plugins/experimental/jax_fingerprint/ja4h/test.cc @@ -78,7 +78,7 @@ class MockDatasource : public Datasource SHA256_CTX sha256ctx; SHA256_Init(&sha256ctx); - for (auto ite : this->_fields) { + for (auto const &ite : this->_fields) { if (this->_should_include_field({ite.first.c_str(), ite.first.size()})) { SHA256_Update(&sha256ctx, ite.first.c_str(), ite.first.size()); } diff --git a/plugins/experimental/rate_limit/sni_selector.cc b/plugins/experimental/rate_limit/sni_selector.cc index 5d992687aa0..02fc08f15b9 100644 --- a/plugins/experimental/rate_limit/sni_selector.cc +++ b/plugins/experimental/rate_limit/sni_selector.cc @@ -149,7 +149,7 @@ SniSelector::yamlParser(const std::string &yaml_file) return false; } Dbg(dbg_ctl, "Adding alias: %s -> %s", alias.c_str(), name.c_str()); - addAlias(alias, limiter_ptr); + addAlias(std::move(alias), limiter_ptr); } } else { TSError("[%s] aliases node is not a sequence", PLUGIN_NAME); diff --git a/plugins/experimental/rate_limit/txn_limiter.cc b/plugins/experimental/rate_limit/txn_limiter.cc index 489e47c0cbb..2e161e2c748 100644 --- a/plugins/experimental/rate_limit/txn_limiter.cc +++ b/plugins/experimental/rate_limit/txn_limiter.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include "txn_limiter.h" @@ -178,7 +179,7 @@ TxnRateLimiter::initialize(int argc, const char *argv[]) _action = TSContScheduleEveryOnPool(_queue_cont, QUEUE_DELAY_TIME.count(), TS_THREAD_POOL_TASK); } - this->initializeMetrics(RATE_LIMITER_TYPE_REMAP, tag, prefix); + this->initializeMetrics(RATE_LIMITER_TYPE_REMAP, std::move(tag), std::move(prefix)); return true; } diff --git a/plugins/experimental/stek_share/log_store.cc b/plugins/experimental/stek_share/log_store.cc index 6abe9d51845..6eab589925e 100644 --- a/plugins/experimental/stek_share/log_store.cc +++ b/plugins/experimental/stek_share/log_store.cc @@ -80,7 +80,7 @@ STEKShareLogStore::append(nuraft::ptr &entry) std::lock_guard l(logs_lock_); size_t idx = start_idx_ + logs_.size() - 1; - logs_[idx] = clone; + logs_[idx] = std::move(clone); return idx; } @@ -205,7 +205,7 @@ STEKShareLogStore::pack(uint64_t index, int32_t cnt) assert(le.get()); nuraft::ptr buf = le->serialize(); size_total += buf->size(); - logs.push_back(buf); + logs.push_back(std::move(buf)); } nuraft::ptr buf_out = nuraft::buffer::alloc(sizeof(int32_t) + cnt * sizeof(int32_t) + size_total); @@ -236,7 +236,7 @@ STEKShareLogStore::apply_pack(uint64_t index, nuraft::buffer &pack) nuraft::ptr le = nuraft::log_entry::deserialize(*buf_local); { std::lock_guard l(logs_lock_); - logs_[cur_idx] = le; + logs_[cur_idx] = std::move(le); } } diff --git a/plugins/experimental/stek_share/state_machine.h b/plugins/experimental/stek_share/state_machine.h index eabe0a87dc5..8033e14a0be 100644 --- a/plugins/experimental/stek_share/state_machine.h +++ b/plugins/experimental/stek_share/state_machine.h @@ -208,7 +208,7 @@ class STEKShareSM : public nuraft::state_machine { std::lock_guard l(snapshot_lock_); - snapshot_ = ctx; + snapshot_ = std::move(ctx); } nuraft::ptr except(nullptr); diff --git a/plugins/experimental/stek_share/state_manager.h b/plugins/experimental/stek_share/state_manager.h index dd0951e6380..b7a48a8bc00 100644 --- a/plugins/experimental/stek_share/state_manager.h +++ b/plugins/experimental/stek_share/state_manager.h @@ -19,6 +19,8 @@ limitations under the License. #pragma once +#include + #include #include "log_store.h" @@ -37,7 +39,7 @@ class STEKShareSMGR : public nuraft::state_mgr int server_id = s.first; std::string endpoint = s.second; nuraft::ptr new_server = nuraft::cs_new(server_id, endpoint); - saved_config_->get_servers().push_back(new_server); + saved_config_->get_servers().push_back(std::move(new_server)); } } diff --git a/plugins/experimental/stek_share/stek_share.cc b/plugins/experimental/stek_share/stek_share.cc index d4e5e4ecce0..1755319331c 100644 --- a/plugins/experimental/stek_share/stek_share.cc +++ b/plugins/experimental/stek_share/stek_share.cc @@ -124,7 +124,7 @@ message_handler(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata) TSError("[%s] Raft initialization failed with new config, retrying with old config.", PLUGIN_NAME); auto config_old = get_scoped_config(true); restore_config(config_old); - if (init_raft(nuraft::cs_new(), config_old) == 0) { + if (init_raft(nuraft::cs_new(), std::move(config_old)) == 0) { Dbg(dbg_ctl, "Server ID: %d, Endpoint: %s", config->server_id, config->endpoint.c_str()); } else { TSEmergency("[%s] Raft initialization failed with old config.", PLUGIN_NAME); @@ -168,7 +168,7 @@ init_raft(nuraft::ptr sm_instance, std::shared_ptr #include #include +#include #include @@ -552,7 +553,7 @@ SessionData::global_session_handler(TSCont /* contp ATS_UNUSED */, TSEvent event TSHttpSsnReenable(ssnp, TS_EVENT_HTTP_CONTINUE); return TS_EVENT_HTTP_CONTINUE; } - ssnData->log_name = log_f; + ssnData->log_name = std::move(log_f); // Write log file beginning to disk ssnData->write_to_disk(beginning); } diff --git a/plugins/traffic_dump/transaction_data.cc b/plugins/traffic_dump/transaction_data.cc index 39f84231474..d8da5aa03c1 100644 --- a/plugins/traffic_dump/transaction_data.cc +++ b/plugins/traffic_dump/transaction_data.cc @@ -331,7 +331,7 @@ TransactionData::write_client_request_node_no_content(TSMBuffer &buffer, TSMLoc std::ostringstream client_request_node; client_request_node << R"(,"client-request":{)"; - auto const http_version = _http_version_from_client_stack; + auto const &http_version = _http_version_from_client_stack; if (http_version == "2") { client_request_node << R"("http2":{)"; diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index 581dae89982..f5a065b0202 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -8335,7 +8335,7 @@ TSSslServerCertUpdate(const char *cert_path, const char *key_path) return TS_ERROR; } // Atomic Swap - cc->setCtx(test_ctx); + cc->setCtx(std::move(test_ctx)); return TS_SUCCESS; } } @@ -8935,7 +8935,7 @@ TSRPCHandlerDone(TSYaml resp) { Dbg(dbg_ctl_rpc_api, ">> Handler seems to be done"); std::lock_guard lock(::rpc::g_rpcHandlingMutex); - auto data = *reinterpret_cast(resp); + auto &data = *reinterpret_cast(resp); ::rpc::g_rpcHandlerResponseData = data; ::rpc::g_rpcHandlerProcessingCompleted = true; ::rpc::g_rpcHandlingCompletion.notify_one(); diff --git a/src/config/ssl_multicert.cc b/src/config/ssl_multicert.cc index 873068df112..c64780113ef 100644 --- a/src/config/ssl_multicert.cc +++ b/src/config/ssl_multicert.cc @@ -249,16 +249,16 @@ SSLMultiCertParser::parse_yaml(std::string_view content) try { YAML::Node config = YAML::Load(std::string(content)); if (config.IsNull()) { - return {result, std::move(errata)}; + return {std::move(result), std::move(errata)}; } if (!config[KEY_SSL_MULTICERT]) { - return {result, swoc::Errata("expected a toplevel 'ssl_multicert' node")}; + return {std::move(result), swoc::Errata("expected a toplevel 'ssl_multicert' node")}; } YAML::Node entries = config[KEY_SSL_MULTICERT]; if (!entries.IsSequence()) { - return {result, swoc::Errata("expected 'ssl_multicert' to be a sequence")}; + return {std::move(result), swoc::Errata("expected 'ssl_multicert' to be a sequence")}; } for (auto const &entry_node : entries) { @@ -279,7 +279,7 @@ SSLMultiCertParser::parse_yaml(std::string_view content) result.push_back(entry_node.as()); } } catch (std::exception const &ex) { - return {result, swoc::Errata("YAML parse error: {}", ex.what())}; + return {std::move(result), swoc::Errata("YAML parse error: {}", ex.what())}; } return {std::move(result), std::move(errata)}; diff --git a/src/iocore/net/SSLCertLookup.cc b/src/iocore/net/SSLCertLookup.cc index bf33d0294f6..c53bf07b68b 100644 --- a/src/iocore/net/SSLCertLookup.cc +++ b/src/iocore/net/SSLCertLookup.cc @@ -433,7 +433,7 @@ SSLCertLookup::getPolicies(const std::string &secret_name, std::setsecond) { + for (auto const &name : iter->second) { SSLCertContext *cc = this->find(name); if (cc) { policies.insert(cc->userconfig); diff --git a/src/iocore/net/SSLNetVConnection.cc b/src/iocore/net/SSLNetVConnection.cc index 8d2abaf7af0..0599ca387a8 100644 --- a/src/iocore/net/SSLNetVConnection.cc +++ b/src/iocore/net/SSLNetVConnection.cc @@ -48,6 +48,7 @@ #include #include #include +#include #if TS_USE_TLS_ASYNC #include @@ -2398,7 +2399,7 @@ SSLNetVConnection::_ssl_connect() if (shared_sess && SSL_set_session(ssl, shared_sess.get())) { // Keep a reference of this shared pointer in the connection - this->client_sess = shared_sess; + this->client_sess = std::move(shared_sess); } } } diff --git a/src/iocore/net/SSLUtils.cc b/src/iocore/net/SSLUtils.cc index 2a1e8cf1e96..45a83f34a81 100644 --- a/src/iocore/net/SSLUtils.cc +++ b/src/iocore/net/SSLUtils.cc @@ -2121,7 +2121,7 @@ SSLMultiCertConfigLoader::load_certs_and_cross_reference_names( for (const char *keyname = key_tok.getNext(); keyname; keyname = key_tok.getNext()) { std::string completeServerKeyPath = Layout::get()->relative_to(params->serverKeyPathOnly, keyname); - data.key_list.push_back(completeServerKeyPath); + data.key_list.push_back(std::move(completeServerKeyPath)); } for (const char *caname = ca_tok.getNext(); caname; caname = ca_tok.getNext()) { @@ -2136,7 +2136,7 @@ SSLMultiCertConfigLoader::load_certs_and_cross_reference_names( int cert_index = 0; for (const char *certname = cert_tok.getNext(); certname; certname = cert_tok.getNext()) { std::string completeServerCertPath = Layout::relative_to(params->serverCertPathOnly, certname); - data.cert_names_list.push_back(completeServerCertPath); + data.cert_names_list.push_back(std::move(completeServerCertPath)); } for (size_t i = 0; i < data.cert_names_list.size(); i++) { @@ -2231,7 +2231,7 @@ SSLMultiCertConfigLoader::load_certs_and_cross_reference_names( if (first_pass) { first_pass = false; - common_names = name_set; + common_names = std::move(name_set); } else { // Check that all elements in common_names are in name_set auto common_iter = common_names.begin(); diff --git a/src/iocore/net/UnixNetAccept.cc b/src/iocore/net/UnixNetAccept.cc index d02c1aacc82..d2abdd43322 100644 --- a/src/iocore/net/UnixNetAccept.cc +++ b/src/iocore/net/UnixNetAccept.cc @@ -135,7 +135,7 @@ net_accept(NetAccept *na, void *ep, bool blockable) if (!vc) { goto Ldone; // note: @a con will clean up the socket when it goes out of scope. } - vc->enable_inbound_connection_tracking(conn_track_group); + vc->enable_inbound_connection_tracking(std::move(conn_track_group)); count++; Metrics::Gauge::increment(net_rsb.connections_currently_open); @@ -420,7 +420,7 @@ NetAccept::do_blocking_accept(EThread *t) if (unlikely(!vc)) { return -1; } - vc->enable_inbound_connection_tracking(conn_track_group); + vc->enable_inbound_connection_tracking(std::move(conn_track_group)); count++; Metrics::Gauge::increment(net_rsb.connections_currently_open); @@ -588,7 +588,7 @@ NetAccept::acceptFastEvent(int event, void *ep) vc = static_cast(this->getNetProcessor()->allocate_vc(e->ethread)); ink_release_assert(vc); - vc->enable_inbound_connection_tracking(conn_track_group); + vc->enable_inbound_connection_tracking(std::move(conn_track_group)); count++; Metrics::Gauge::increment(net_rsb.connections_currently_open); diff --git a/src/proxy/HostStatus.cc b/src/proxy/HostStatus.cc index f593a1c34e2..e9bd46a2a8d 100644 --- a/src/proxy/HostStatus.cc +++ b/src/proxy/HostStatus.cc @@ -309,7 +309,7 @@ HostStatus::getAllHostStatuses(std::vector &hosts) h.hostname = hsts.first; ss << *hsts.second; h.status = ss.str(); - hosts.push_back(h); + hosts.push_back(std::move(h)); } } } diff --git a/src/proxy/http/PreWarmManager.cc b/src/proxy/http/PreWarmManager.cc index 594fc242237..b0f9e1888d9 100644 --- a/src/proxy/http/PreWarmManager.cc +++ b/src/proxy/http/PreWarmManager.cc @@ -924,7 +924,7 @@ PreWarmQueue::_reconfigure() // copy from old info const Info &old_info = res->second; - new_map[dst] = Info{old_info.init_list, old_info.open_list, conf, old_info.stats_ids, old_info.stat}; + new_map[dst] = Info{old_info.init_list, old_info.open_list, std::move(conf), old_info.stats_ids, old_info.stat}; } else { // make new info PreWarm::SPtrConstStatsIds stats_ids; @@ -937,7 +937,7 @@ PreWarmQueue::_reconfigure() Queue *init_list = new Queue(); Queue *open_list = new Queue(); - new_map[dst] = Info{init_list, open_list, conf, stats_ids, {}}; + new_map[dst] = Info{init_list, open_list, std::move(conf), std::move(stats_ids), {}}; } } diff --git a/src/traffic_ctl/CtrlCommands.cc b/src/traffic_ctl/CtrlCommands.cc index 514c5d17098..eee6b1a1e3f 100644 --- a/src/traffic_ctl/CtrlCommands.cc +++ b/src/traffic_ctl/CtrlCommands.cc @@ -990,7 +990,7 @@ PluginCommand::plugin_msg() // have a value params.str = msgs[1]; } - BasicPluginMessageRequest request{params}; + BasicPluginMessageRequest request{std::move(params)}; auto response = invoke_rpc(request); _printer->write_output(response); } diff --git a/src/traffic_ctl/jsonrpc/ctrl_yaml_codecs.h b/src/traffic_ctl/jsonrpc/ctrl_yaml_codecs.h index 0eff4952b58..23023f7de68 100644 --- a/src/traffic_ctl/jsonrpc/ctrl_yaml_codecs.h +++ b/src/traffic_ctl/jsonrpc/ctrl_yaml_codecs.h @@ -299,7 +299,7 @@ template <> struct convert { HostStatusLookUpResponse::HostStatusInfo hi; hi.hostName = item["hostname"].Scalar(); hi.status = item["status"].Scalar(); - info.statusList.push_back(hi); + info.statusList.push_back(std::move(hi)); } for (auto &&item : errorList) { info.errorList.push_back(item.Scalar()); diff --git a/src/tscore/ArgParser.cc b/src/tscore/ArgParser.cc index 90c3c2f5e43..fb9a2a708f3 100644 --- a/src/tscore/ArgParser.cc +++ b/src/tscore/ArgParser.cc @@ -301,8 +301,8 @@ ArgParser::Command::add_option(std::string const &long_option, std::string const { std::string lookup_key = key.empty() ? long_option.substr(2) : key; check_option(long_option, short_option, lookup_key); - _option_list[long_option] = {long_option, short_option == "-" ? "" : short_option, description, envvar, arg_num, default_value, - lookup_key}; + _option_list[long_option] = { + long_option, short_option == "-" ? "" : short_option, description, envvar, arg_num, default_value, std::move(lookup_key)}; if (short_option != "-" && !short_option.empty()) { _option_map[short_option] = long_option; } diff --git a/src/tscore/Layout.cc b/src/tscore/Layout.cc index 629ee91acf0..0e2a1bb9447 100644 --- a/src/tscore/Layout.cc +++ b/src/tscore/Layout.cc @@ -161,7 +161,7 @@ Layout::Layout(std::string_view const _prefix) if ((len + 1) > PATH_NAME_MAX) { ink_fatal("TS_ROOT environment variable is too big: %d, max %d\n", len, PATH_NAME_MAX - 1); } - path = env_path; + path = std::move(env_path); while (path.back() == '/') { path.pop_back(); } @@ -169,7 +169,7 @@ Layout::Layout(std::string_view const _prefix) // Use compile time --prefix path = TS_BUILD_PREFIX; } - prefix = path; + prefix = std::move(path); } exec_prefix = layout_relative(prefix, TS_BUILD_EXEC_PREFIX); bindir = layout_relative(prefix, TS_BUILD_BINDIR); diff --git a/src/tscore/runroot.cc b/src/tscore/runroot.cc index b624c61d38b..14036a2db82 100644 --- a/src/tscore/runroot.cc +++ b/src/tscore/runroot.cc @@ -29,6 +29,7 @@ #include "tscore/Layout.h" #include "tscore/runroot.h" #include +#include static std::string runroot_file = {}; @@ -110,7 +111,7 @@ runroot_extra_handling(const char *executable, bool json) if (env_val) { path = get_yaml_path(env_val); if (!path.empty()) { - runroot_file = path; + runroot_file = std::move(path); if (!json) { ink_notice("using the environment variable TS_RUNROOT"); } @@ -124,7 +125,7 @@ runroot_extra_handling(const char *executable, bool json) if (getcwd(cwd, sizeof(cwd)) != nullptr) { path = get_parent_yaml_path(cwd); if (!path.empty()) { - runroot_file = path; + runroot_file = std::move(path); if (!json) { ink_notice("using cwd as TS_RUNROOT"); } @@ -138,7 +139,7 @@ runroot_extra_handling(const char *executable, bool json) bindir = bindir.substr(0, bindir.find_last_of('/')); // getting the bin dir not executable path path = get_parent_yaml_path(bindir); if (!path.empty()) { - runroot_file = path; + runroot_file = std::move(path); if (!json) { ink_notice("using the installed dir as TS_RUNROOT"); } @@ -161,7 +162,7 @@ argparser_runroot_handler(std::string const &value, const char *executable, bool if (!json) { ink_notice("using command line path as RUNROOT"); } - runroot_file = path; + runroot_file = std::move(path); return; } else if (!json) { ink_warning("Unable to access runroot: '%s'", value.c_str()); @@ -201,7 +202,7 @@ runroot_handler(const char **argv, bool json) if (!json) { ink_notice("using command line path as RUNROOT"); } - runroot_file = path; + runroot_file = std::move(path); return; } else if (!json) { ink_warning("Unable to access runroot: '%s'", value.c_str()); @@ -250,7 +251,7 @@ runroot_map(const std::string &file) if (value[0] != '/') { value = Layout::relative_to(prefix, value); } - map[it.first.as()] = value; + map[it.first.as()] = std::move(value); } } catch (YAML::Exception &e) { ink_warning("Unable to read '%s': %s", file.c_str(), e.what()); diff --git a/src/tsutil/Metrics.cc b/src/tsutil/Metrics.cc index 92bcb3bf6b0..71d188775d7 100644 --- a/src/tsutil/Metrics.cc +++ b/src/tsutil/Metrics.cc @@ -254,7 +254,7 @@ namespace details push_back(const DerivedMetric &m) { std::lock_guard l(metrics_lock); - metrics.push_back(std::move(m)); + metrics.push_back(m); } static DerivativeMetrics & From 776c679ca1fc8702fe4b759dd04115abe4a01e21 Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Fri, 14 Aug 2026 11:36:21 -0700 Subject: [PATCH 2/2] Bind the RPC handler response node by const reference TSRPCHandlerDone only reads the node, so casting to a const pointer and binding a const reference says that at the call site instead of handing out a mutable reference to a caller-owned node. --- src/api/InkAPI.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index f5a065b0202..18098d7aa61 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -8935,7 +8935,7 @@ TSRPCHandlerDone(TSYaml resp) { Dbg(dbg_ctl_rpc_api, ">> Handler seems to be done"); std::lock_guard lock(::rpc::g_rpcHandlingMutex); - auto &data = *reinterpret_cast(resp); + auto const &data = *reinterpret_cast(resp); ::rpc::g_rpcHandlerResponseData = data; ::rpc::g_rpcHandlerProcessingCompleted = true; ::rpc::g_rpcHandlingCompletion.notify_one();