]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Accept NULL @list in vshCompleterFilter()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 2 Feb 2021 09:39:19 +0000 (10:39 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Feb 2021 10:51:59 +0000 (11:51 +0100)
The aim of vshCompleterFilter() is to take a string list and a
prefix and remove all strings from the list that don't have the
desired prefix. The function is used to filter out those strings
returned by a completer callback that don't correspond with
user's (partial) input. For instance, domain name completer
virshDomainNameCompleter() returns all domain names and then
vshCompleterFilter() refines the list so that only domains with
correct prefix of their name are offered to user. This was a
design choice - it allows us to have shorter completers as they
do not have to copy the list filtering over and over.

Having said all of that, it may happen that a completer does not
return anything (e.g. there is no domain in requested state,
virsh is not connected and thus completer exited early, etc.). In
that case, the string list is NULL and vshCompleterFilter() can
simply return early.

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

index bb8b90b08eb59e5cc92f0a62314a17f941d9cd70..2df3b0741a465aeb8934d637a2530c0eaabe69a5 100644 (file)
@@ -2703,7 +2703,7 @@ vshCompleterFilter(char ***list,
     size_t i;
 
     if (!list || !*list)
-        return -1;
+        return 0;
 
     list_len = virStringListLength((const char **) *list);
     newList = g_new0(char *, list_len + 1);
@@ -2802,9 +2802,8 @@ vshReadlineParse(const char *text, int state)
                 /* For string list returned by completer we have to do
                  * filtering based on @text because completer returns all
                  * possible strings. */
-                if (completer_list &&
-                    (vshCompleterFilter(&completer_list, text) < 0 ||
-                     virStringListMerge(&list, &completer_list) < 0)) {
+                if (vshCompleterFilter(&completer_list, text) < 0 ||
+                    virStringListMerge(&list, &completer_list) < 0) {
                     goto cleanup;
                 }
             }