Skip to contentSkip to conversation

block: Pacify Coverity

PATCH Applied Markus Armbruster 2 participants 4 messages Jun 26, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

cover block: Pacify Coverity

Markus Armbruster (2):
block-qdict: Pacify Coverity after commit f1b34a248e9 block/crypto: Pacify Coverity after commit f853465aacb

 block/crypto.c        |  4 ++--
 qobject/block-qdict.c | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 block-qdict: Pacify Coverity after commit f1b34a248e9

Commit f1b34a248e9 replaced less-than-obvious test in qdict_flatten_qdict() by the obvious one. Sadly, it made something else non-obvious: the fact that @new_key passed to qdict_put_obj() can't be null, because that depends on the function's precondition (target == qdict) == !prefix.

Tweak the function some more to help Coverity and human readers alike.

Fixes CID 1393620
---
 qobject/block-qdict.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
qobject/block-qdict.c +8 -8
index 36129e7379..80c653013f 100644
@@ -97,7 +97,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
     const QDictEntry *entry, *next;
     QDict *dict_val;
     QList *list_val;
-    char *new_key;
+    char *key, *new_key;
 
     entry = qdict_first(qdict);
 
@@ -106,10 +106,12 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
         value = qdict_entry_value(entry);
         dict_val = qobject_to(QDict, value);
         list_val = qobject_to(QList, value);
-        new_key = NULL;
 
         if (prefix) {
-            new_key = g_strdup_printf("%s.%s", prefix, entry->key);
+            key = new_key = g_strdup_printf("%s.%s", prefix, entry->key);
+        } else {
+            key = entry->key;
+            new_key = NULL;
         }
 
         /*
@@ -125,19 +127,17 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
          * well advised not to modify them altogether.)
          */
         if (dict_val && qdict_size(dict_val)) {
-            qdict_flatten_qdict(dict_val, target,
-                                new_key ? new_key : entry->key);
+            qdict_flatten_qdict(dict_val, target, key);
             if (target == qdict) {
                 qdict_del(qdict, entry->key);
             }
         } else if (list_val && !qlist_empty(list_val)) {
-            qdict_flatten_qlist(list_val, target,
-                                new_key ? new_key : entry->key);
+            qdict_flatten_qlist(list_val, target, key);
             if (target == qdict) {
                 qdict_del(qdict, entry->key);
             }
         } else if (target != qdict) {
-            qdict_put_obj(target, new_key, qobject_ref(value));
+            qdict_put_obj(target, key, qobject_ref(value));
         }
 
         g_free(new_key);
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 block/crypto: Pacify Coverity after commit f853465aacb

In reply to Markus Armbruster

Coverity can't see that qobject_input_visitor_new_flat_confused() returns non-null when it doesn't set @local_err. Check the return value instead, like all the other callers do.

Fixes CID 1393615
Fixes CID 1393616
---
 block/crypto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/crypto.c +2 -2
index 82091c5f70..aaa8fb7530 100644
@@ -160,7 +160,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format,
     ret->format = format;
 
     v = qobject_input_visitor_new_flat_confused(opts, &local_err);
-    if (local_err) {
+    if (!v) {
         goto out;
     }
 
@@ -214,7 +214,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format,
     ret->format = format;
 
     v = qobject_input_visitor_new_flat_confused(opts, &local_err);
-    if (local_err) {
+    if (!v) {
         goto out;
     }
 
Signature · 1 line
2.17.1
Applied
#3 lore raw
In reply to Markus Armbruster

Am 26.06.2018 um 10:05 hat Markus Armbruster geschrieben:

Quoted 3 lines

Markus Armbruster (2):
block-qdict: Pacify Coverity after commit f1b34a248e9 block/crypto: Pacify Coverity after commit f853465aacb

Thanks, applied to the block branch.

Kevin