From 3059a30da9707055ca14d24f50469f7427901caf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 21 Feb 2019 09:47:23 +0100 Subject: [PATCH] cli: use nm_utils_bin2hexstr_full() in nmcli to convert bytes to string - it's less lines of code (for the caller). - it's a function that can be easier unit-tested on its own. Possibly there are already other unit-tests that cover it. - it's more efficient than the GString based implementation. - it reuses our one and only bin-to-hexstr implementation. --- clients/common/nm-meta-setting-desc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 05a8689b91..c112343aeb 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -1513,18 +1513,16 @@ bytes_to_string (GBytes *bytes) { const guint8 *data; gsize len; - GString *cert = NULL; - int i; if (!bytes) return NULL; + data = g_bytes_get_data (bytes, &len); - - cert = g_string_new (NULL); - for (i = 0; i < len; i++) - g_string_append_printf (cert, "%02X", data[i]); - - return g_string_free (cert, FALSE); + return nm_utils_bin2hexstr_full (data, + len, + '\0', + TRUE, + NULL); } static char *