[PATCH 09/39] virJSONValueObjectDeflattenWorker: use g_strsplit instead of virStringSplitCount

Peter Krempa pkrempa at redhat.com
Thu Apr 1 13:52:08 UTC 2021


The presence of the second element can be checked by looking at it
directly.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/util/virjson.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 82081db870..f376490288 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -2029,7 +2029,6 @@ virJSONValueObjectDeflattenWorker(const char *key,
     g_autoptr(virJSONValue) newval = NULL;
     virJSONValuePtr existobj;
     g_auto(GStrv) tokens = NULL;
-    size_t ntokens = 0;

     /* non-nested keys only need to be copied */
     if (!strchr(key, '.')) {
@@ -2054,10 +2053,10 @@ virJSONValueObjectDeflattenWorker(const char *key,
         return 0;
     }

-    if (!(tokens = virStringSplitCount(key, ".", 2, &ntokens)))
+    if (!(tokens = g_strsplit(key, ".", 2)))
         return -1;

-    if (ntokens != 2) {
+    if (!tokens[0] || !tokens[1]) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("invalid nested value key '%s'"), key);
         return -1;
-- 
2.29.2




More information about the libvir-list mailing list