From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaTq2-0007pi-An for qemu-devel@nongnu.org; Fri, 11 Sep 2015 15:18:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaTq1-0001sR-9p for qemu-devel@nongnu.org; Fri, 11 Sep 2015 15:18:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37726) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaTq0-0001s8-US for qemu-devel@nongnu.org; Fri, 11 Sep 2015 15:18:21 -0400 From: Markus Armbruster Date: Fri, 11 Sep 2015 21:18:03 +0200 Message-Id: <1441999089-28960-21-git-send-email-armbru@redhat.com> In-Reply-To: <1441999089-28960-1-git-send-email-armbru@redhat.com> References: <1441999089-28960-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mdroth@linux.vnet.ibm.com Before commit 1d10b44, it crashed. Since then, it returns NULL, with a FIXME comment. The FIXME is valid: code that assumes QObject * can't be null exists. I'm not aware of a way to feed this problematic return value to code that actually chokes on null in the current code, but the next few commits will create one. Commit 481b002 solved a very similar problem by introducing a special null QObject. Use it here, and drop the FIXME. Update the test accordingly. Signed-off-by: Markus Armbruster --- qapi/qmp-output-visitor.c | 3 +-- tests/test-qmp-output-visitor.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index efc19d5..2d6083e 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -66,9 +66,8 @@ static QObject *qmp_output_first(QmpOutputVisitor *qov) { QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack); - /* FIXME - find a better way to deal with NULL values */ if (!e) { - return NULL; + return qnull(); } return e->value; diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index 338ada0..256bffd 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -485,7 +485,7 @@ static void test_visitor_out_empty(TestOutputVisitorData *data, QObject *arg; arg = qmp_output_get_qobject(data->qov); - g_assert(!arg); + g_assert(qobject_type(arg) == QTYPE_QNULL); } static void init_native_list(UserDefNativeListUnion *cvalue) -- 2.4.3