From 8efeb3688cd25a53c324f595f774f80276f90d65 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Jun 2017 14:28:58 +0200 Subject: [PATCH] cli: fix returning no results in complete function For consistency, never return an empty array @values. If we have an empty array, instead return NULL. Also fixes commit afac7621a "clients: return NULL array on auto-completion failure", which claims that readline crashes with empty strv arrays. Fixes: afac7621ae3b306701fa388e31f57b082a5b1510 --- clients/common/nm-meta-setting-access.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c index 47869f95c6..cd7ef783c4 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -283,10 +283,18 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, nm_assert (!*out_to_free || values == (const char *const*) *out_to_free); - if (!text || !text[0] || !values || !values[0]) + if (!values) + return NULL; + + if (!values[0]) { + nm_clear_g_free (out_to_free); + return NULL; + } + + if (!text || !text[0]) return values; - /* for convenience, we all the complete_fcn() implementations to + /* for convenience, we allow the complete_fcn() implementations to * ignore "text". We filter out invalid matches here. */ text_len = strlen (text);