cli: reuse NMStrBuf in ac_overview()

No need to mix GString and NMStrBuf.
This commit is contained in:
Thomas Haller
2023-11-20 11:02:37 +01:00
parent 6f53f390a2
commit 39d900593b

View File

@@ -1411,27 +1411,28 @@ device_overview(NmCli *nmc, NMDevice *device)
static void static void
ac_overview(NmCli *nmc, NMActiveConnection *ac) ac_overview(NmCli *nmc, NMActiveConnection *ac)
{ {
GString *outbuf = g_string_sized_new(80); nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_488, FALSE);
nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE);
int IS_IPv4; int IS_IPv4;
if (nm_active_connection_get_controller(ac)) { if (nm_active_connection_get_controller(ac)) {
g_string_append_printf(outbuf, nm_str_buf_append_printf(&str,
"%s %s, ", "%s %s, ",
_("master"), _("master"),
nm_device_get_iface(nm_active_connection_get_controller(ac))); nm_device_get_iface(nm_active_connection_get_controller(ac)));
} }
if (nm_active_connection_get_vpn(ac)) if (nm_active_connection_get_vpn(ac))
g_string_append_printf(outbuf, "%s, ", _("VPN")); nm_str_buf_append_printf(&str, "%s, ", _("VPN"));
if (nm_active_connection_get_default(ac)) if (nm_active_connection_get_default(ac))
g_string_append_printf(outbuf, "%s, ", _("ip4 default")); nm_str_buf_append_printf(&str, "%s, ", _("ip4 default"));
if (nm_active_connection_get_default6(ac)) if (nm_active_connection_get_default6(ac))
g_string_append_printf(outbuf, "%s, ", _("ip6 default")); nm_str_buf_append_printf(&str, "%s, ", _("ip6 default"));
if (outbuf->len >= 2) { if (str.len >= 2) {
g_string_truncate(outbuf, outbuf->len - 2); nm_str_buf_set_size(&str, str.len - 2u, TRUE, FALSE);
nmc_print("\t%s\n", outbuf->str); nmc_print("\t%s\n", nm_str_buf_get_str(&str));
} }
nm_str_buf_reset(&str);
for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) { for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) {
NMIPConfig *ip; NMIPConfig *ip;
const GPtrArray *p; const GPtrArray *p;
@@ -1462,8 +1463,6 @@ ac_overview(NmCli *nmc, NMActiveConnection *ac)
nmc_print("\troute%c %s\n", IS_IPv4 ? '4' : '6', nm_str_buf_get_str(&str)); nmc_print("\troute%c %s\n", IS_IPv4 ? '4' : '6', nm_str_buf_get_str(&str));
} }
} }
g_string_free(outbuf, TRUE);
} }
void void