]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Prefer g_strdup_printf() over g_snprintf() in vshReadlineOptionsGenerator()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 2 Feb 2021 10:05:47 +0000 (11:05 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Feb 2021 10:51:59 +0000 (11:51 +0100)
The vshReadlineOptionsGenerator() function returns a string list
of all --options for given command. But the way that individual
items on the list are allocated can be written better.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tools/vsh.c

index 2df3b0741a465aeb8934d637a2530c0eaabe69a5..201b7ba6d16f77fefb723b468537f1de14ea8ee8 100644 (file)
@@ -2627,7 +2627,6 @@ vshReadlineOptionsGenerator(const char *text,
         const char *name = cmd->opts[list_index].name;
         bool exists = false;
         vshCmdOpt *opt =  last->opts;
-        size_t name_len;
 
         /* Skip aliases, we do not report them in help output either. */
         if (cmd->opts[list_index].type == VSH_OT_ALIAS)
@@ -2660,9 +2659,7 @@ vshReadlineOptionsGenerator(const char *text,
             return NULL;
         }
 
-        name_len = strlen(name);
-        ret[ret_size] = g_new0(char, name_len + 3);
-        g_snprintf(ret[ret_size], name_len + 3,  "--%s", name);
+        ret[ret_size] = g_strdup_printf("--%s", name);
         ret_size++;
         /* Terminate the string list properly. */
         ret[ret_size] = NULL;