Don't re-calculate the string list length on every iteration. Convert the loop to NULL-terminated iteration. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/util/virpolkit.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c index 1d6be443f7..c657c45681 100644 --- a/src/util/virpolkit.c +++ b/src/util/virpolkit.c @@ -75,7 +75,7 @@ int virPolkitCheckAuth(const char *actionid, gboolean is_authorized; gboolean is_challenge; bool is_dismissed = false; - size_t i; + const char **next; if (!(sysbus = virGDBusGetSystemBus())) return -1; @@ -90,8 +90,15 @@ int virPolkitCheckAuth(const char *actionid, gprocess = g_variant_builder_end(&builder); g_variant_builder_init(&builder, G_VARIANT_TYPE("a{ss}")); - for (i = 0; i < virStringListLength(details); i += 2) - g_variant_builder_add(&builder, "{ss}", details[i], details[i + 1]); + + if (details) { + for (next = details; *next; next++) { + const char *detail1 = *(next++); + const char *detail2 = *next; + g_variant_builder_add(&builder, "{ss}", detail1, detail2); + } + } + gdetails = g_variant_builder_end(&builder); message = g_variant_new("((s@a{sv})s@a{ss}us)", -- 2.29.2