From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGwl7-0002zS-Nq for qemu-devel@nongnu.org; Wed, 06 Jan 2016 17:40:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGwl4-0005ma-HK for qemu-devel@nongnu.org; Wed, 06 Jan 2016 17:40:49 -0500 Received: from resqmta-po-08v.sys.comcast.net ([96.114.154.167]:41732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGwl4-0005mV-AN for qemu-devel@nongnu.org; Wed, 06 Jan 2016 17:40:46 -0500 From: Eric Blake Date: Wed, 6 Jan 2016 15:40:28 -0700 Message-Id: <1452120028-30055-1-git-send-email-eblake@redhat.com> In-Reply-To: <1450717720-9627-24-git-send-email-eblake@redhat.com> References: <1450717720-9627-24-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v8 23.5/35] qmp: Tighten output visitor rules, part 2 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, armbru@redhat.com, Michael Roth Nothing was using the return value of qmp_output_pop(). Also, adding a parameter will let us diagnose any programming bugs due to mismatched push(struct)/pop(list) or push(list)/pop(struct). Signed-off-by: Eric Blake --- v9: new patch; probably worth squashing into 23/35 --- qapi/qmp-output-visitor.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index f2c39c5..8a297a6 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -1,7 +1,7 @@ /* * Core Definitions for QAPI/QMP Command Registry * - * Copyright (C) 2015 Red Hat, Inc. + * Copyright (C) 2015-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * * Authors: @@ -57,17 +57,15 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value) QTAILQ_INSERT_HEAD(&qov->stack, e, node); } -/* Grab and remove the most recent QObject from the stack */ -static QObject *qmp_output_pop(QmpOutputVisitor *qov) +/* Remove the most recent QObject with given type from the stack */ +static void qmp_output_pop(QmpOutputVisitor *qov, QType type) { QStackEntry *e = QTAILQ_FIRST(&qov->stack); - QObject *value; assert(e); QTAILQ_REMOVE(&qov->stack, e, node); - value = e->value; + assert(qobject_type(e->value) == type); g_free(e); - return value; } /* Grab the most recent QObject from the stack, if any */ @@ -120,7 +118,7 @@ static void qmp_output_start_struct(Visitor *v, const char *name, void **obj, static void qmp_output_end_struct(Visitor *v, Error **errp) { QmpOutputVisitor *qov = to_qov(v); - qmp_output_pop(qov); + qmp_output_pop(qov, QTYPE_QDICT); } static void qmp_output_start_list(Visitor *v, const char *name, Error **errp) @@ -151,7 +149,7 @@ static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp, static void qmp_output_end_list(Visitor *v) { QmpOutputVisitor *qov = to_qov(v); - qmp_output_pop(qov); + qmp_output_pop(qov, QTYPE_QLIST); } static void qmp_output_type_int64(Visitor *v, const char *name, int64_t *obj, -- 2.4.3