26ba25
From 901ef4e58539427f6a26e134d915e02db0fd0df3 Mon Sep 17 00:00:00 2001
26ba25
From: Markus Armbruster <armbru@redhat.com>
26ba25
Date: Mon, 18 Jun 2018 08:43:08 +0200
26ba25
Subject: [PATCH 010/268] qobject: Use qobject_to() instead of type cast
26ba25
MIME-Version: 1.0
26ba25
Content-Type: text/plain; charset=UTF-8
26ba25
Content-Transfer-Encoding: 8bit
26ba25
26ba25
RH-Author: Markus Armbruster <armbru@redhat.com>
26ba25
Message-id: <20180618084330.30009-2-armbru@redhat.com>
26ba25
Patchwork-id: 80732
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 01/23] qobject: Use qobject_to() instead of type cast
26ba25
Bugzilla: 1557995
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
26ba25
The proper way to convert from (abstract) QObject to a (concrete)
26ba25
subtype is qobject_to().  Look for offenders that type cast instead:
26ba25
26ba25
    $ git-grep '(Q[A-Z][a-z]* \*)'
26ba25
    hmp.c:    qmp_device_add((QDict *)qdict, NULL, &err;;
26ba25
    include/qapi/qmp/qobject.h:        return (QObject *)obj;
26ba25
    qobject/qobject.c:static void (*qdestroy[QTYPE__MAX])(QObject *) = {
26ba25
    tests/check-qdict.c:    dst = (QDict *)qdict_crumple(src, &error_abort);
26ba25
26ba25
The first two cast away const, the third isn't a type cast.  Fix the
26ba25
fourth.
26ba25
26ba25
Signed-off-by: Markus Armbruster <armbru@redhat.com>
26ba25
Message-Id: <20180426152805.8469-1-armbru@redhat.com>
26ba25
Reviewed-by: Eric Blake <eblake@redhat.com>
26ba25
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
26ba25
(cherry picked from commit 46cfbf13b06d551072ed17fbfca67c103edf814f)
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 tests/check-qdict.c | 2 +-
26ba25
 1 file changed, 1 insertion(+), 1 deletion(-)
26ba25
26ba25
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
26ba25
index 2e73c2f..08d4303 100644
26ba25
--- a/tests/check-qdict.c
26ba25
+++ b/tests/check-qdict.c
26ba25
@@ -657,7 +657,7 @@ static void qdict_crumple_test_empty(void)
26ba25
 
26ba25
     src = qdict_new();
26ba25
 
26ba25
-    dst = (QDict *)qdict_crumple(src, &error_abort);
26ba25
+    dst = qobject_to(QDict, qdict_crumple(src, &error_abort));
26ba25
 
26ba25
     g_assert_cmpint(qdict_size(dst), ==, 0);
26ba25
 
26ba25
-- 
26ba25
1.8.3.1
26ba25