cloud-setup: don't use a GString in _get_config_ips_list_cb()

nm_utils_parse_next_line() operates on the response buffer obtained
from NMHttpClient. We own this buffer, and we also can rely on the fact
that the buffer has a trailing NUL byte after the data.

There is no need to clone the string to a GString, just use it directly.
This commit is contained in:
Thomas Haller 2020-06-29 09:52:34 +02:00
parent c9c54709b8
commit 62aec7acd3
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -255,21 +255,20 @@ _get_config_ips_list_cb (GObject *source,
&response_len,
&line,
&line_len)) {
nm_auto_free_gstring GString *gstr = NULL;
gint64 fip_index;
gstr = g_string_new_len (line, line_len);
fip_index = _nm_utils_ascii_str_to_int64 (gstr->str, 10, 0, G_MAXINT64, -1);
/* Truncate the string. It's safe to do, because we own @response_data an it has an
* extra NUL character after the buffer. */
((char *) line)[line_len] = '\0';
if (fip_index < 0) {
fip_index = _nm_utils_ascii_str_to_int64 (line, 10, 0, G_MAXINT64, -1);
if (fip_index < 0)
continue;
}
g_string_printf (gstr,
"%"G_GSSIZE_FORMAT"/forwarded-ips/%"G_GINT64_FORMAT,
iface_data->iface_idx,
fip_index);
g_ptr_array_add (uri_arr, g_string_free (g_steal_pointer (&gstr), FALSE));
g_ptr_array_add (uri_arr,
g_strdup_printf ("%"G_GSSIZE_FORMAT"/forwarded-ips/%"G_GINT64_FORMAT,
iface_data->iface_idx,
fip_index));
}
iface_data->n_fips_pending = uri_arr->len;