diff mbox

[01/14] qdict: Make qdict_get_qlist() safe like qdict_get_qdict()

Message ID 1487363905-9480-2-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Feb. 17, 2017, 8:38 p.m. UTC
Commit 89cad9f changed qdict_get_qdict() to return NULL instead of
crash when the key doesn't exist or its value isn't a QDict.
Commit 2d6421a neglected to do the same for qdict_get_qlist().
Correct that, and update the function comments.

qdict_get_obj() is now unused, remove.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qobject/qdict.c | 30 +++---------------------------
 1 file changed, 3 insertions(+), 27 deletions(-)

Comments

Eric Blake Feb. 17, 2017, 10:29 p.m. UTC | #1
On 02/17/2017 02:38 PM, Markus Armbruster wrote:
> Commit 89cad9f changed qdict_get_qdict() to return NULL instead of
> crash when the key doesn't exist or its value isn't a QDict.
> Commit 2d6421a neglected to do the same for qdict_get_qlist().
> Correct that, and update the function comments.
> 
> qdict_get_obj() is now unused, remove.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qobject/qdict.c | 30 +++---------------------------
>  1 file changed, 3 insertions(+), 27 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/qobject/qdict.c b/qobject/qdict.c
index 197b0fb..b0c5364 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -178,20 +178,6 @@  size_t qdict_size(const QDict *qdict)
 }
 
 /**
- * qdict_get_obj(): Get a QObject of a specific type
- */
-static QObject *qdict_get_obj(const QDict *qdict, const char *key, QType type)
-{
-    QObject *obj;
-
-    obj = qdict_get(qdict, key);
-    assert(obj != NULL);
-    assert(qobject_type(obj) == type);
-
-    return obj;
-}
-
-/**
  * qdict_get_double(): Get an number mapped by 'key'
  *
  * This function assumes that 'key' exists and it stores a
@@ -241,25 +227,15 @@  bool qdict_get_bool(const QDict *qdict, const char *key)
 }
 
 /**
- * qdict_get_qlist(): Get the QList mapped by 'key'
- *
- * This function assumes that 'key' exists and it stores a
- * QList object.
- *
- * Return QList mapped by 'key'.
+ * qdict_get_qlist(): If @qdict maps @key to a QList, return it, else NULL.
  */
 QList *qdict_get_qlist(const QDict *qdict, const char *key)
 {
-    return qobject_to_qlist(qdict_get_obj(qdict, key, QTYPE_QLIST));
+    return qobject_to_qlist(qdict_get(qdict, key));
 }
 
 /**
- * qdict_get_qdict(): Get the QDict mapped by 'key'
- *
- * This function assumes that 'key' exists and it stores a
- * QDict object.
- *
- * Return QDict mapped by 'key'.
+ * qdict_get_qdict(): If @qdict maps @key to a QDict, return it, else NULL.
  */
 QDict *qdict_get_qdict(const QDict *qdict, const char *key)
 {