daemon: fix print_cn command when 0 connections

Deferencing the result of `std::max_element()` when `res.connections` has 0 elements leads to UB, and segfaults in practice.

Co-authored-by: iamamyth <user@example.com>
(cherry picked from commit 7c543c82205c3522510e8da616edc795922ce9f3)
This commit is contained in:
jeffro256
2026-10-04 18:50:19 -04:00
committed by such-gitea
parent 83793218ce
commit 109c08f189
+3 -6
View File
@@ -645,12 +645,9 @@ bool t_rpc_command_executor::print_connections() {
}
}
auto longest_host = *std::max_element(res.connections.begin(), res.connections.end(),
[](const auto &info1, const auto &info2)
{
return info1.address.length() < info2.address.length();
});
int host_field_width = std::max(15, 8 + (int) longest_host.address.length());
int host_field_width = 15;
for (const auto &conn : res.connections)
host_field_width = std::max(host_field_width, 8 + (int) conn.address.length());
tools::msg_writer() << std::setw(host_field_width) << std::left << "Remote Host"
<< std::setw(8) << "Type"