From patchwork Thu Apr 28 16:02:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8972251 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 872E39F1C1 for ; Thu, 28 Apr 2016 16:04:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD6AC20138 for ; Thu, 28 Apr 2016 16:04:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D70220107 for ; Thu, 28 Apr 2016 16:04:12 +0000 (UTC) Received: from localhost ([::1]:49960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avoQE-0000UT-Vp for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Apr 2016 12:04:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avoQ5-0000SF-Kj for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:04:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avoQ0-0001kC-Ki for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:04:01 -0400 Received: from resqmta-po-03v.sys.comcast.net ([96.114.154.162]:38234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avoQ0-0001k8-Do for qemu-devel@nongnu.org; Thu, 28 Apr 2016 12:03:56 -0400 Received: from resomta-po-17v.sys.comcast.net ([96.114.154.241]) by comcast with SMTP id voORaxRbkYPZXvoP0aPNdx; Thu, 28 Apr 2016 16:02:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1461859374; bh=frLcA5e+qmI7UuykOatfRbBgGGdaVO8CAobBUwidYV0=; h=Received:Received:From:To:Subject:Date:Message-Id; b=EWTTBDWTWv5MaWAp8pjKDp7IhopTpza+1vIBhRLpFNvYFzbgF/5wek5ZmeX5nFfPF wUf91XGmc81SZeIgGJ7CzJnKXF9+sZzTl4lVe57QnymHGBJOMvXZ/ctZ6dPloz9MTO wVjlEMQavPzpPV9Pi0xu2g+6nsNsi1lvlwtJZGvM7Gj834IJxicOsko/zqbT25eCRZ kR3gawn0cEfEqtrm5t3ZJ5x7vt9LYKfdrTY/gmU92tS078gI97XbPTZIUJTVO4m2l5 BZSobKaJxdUGr2pBNcaZdxMClbWAtTlbp25ZXJ/3M82LiAkjGuZ8SkjJ248cP+JvBA FtokJYwNyAzTA== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-17v.sys.comcast.net with comcast id ns2q1s0012fD5rL01s2udd; Thu, 28 Apr 2016 16:02:54 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 28 Apr 2016 10:02:45 -0600 Message-Id: <1461859365-32191-1-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1461801715-24307-3-git-send-email-eblake@redhat.com> References: <1461801715-24307-3-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.114.154.162 Subject: [Qemu-devel] [PATCH v15 02A/23] fixup! qapi: Guarantee NULL obj on input visitor callback error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [Updated commit message:] Our existing input visitors were not very consistent on errors in a function taking 'TYPE **obj' (that is, start_struct(), start_alternate(), type_str(), and type_any(). next_list() is similar, except that since commit 08f9541, it can't fail). While all of them set '*obj' to allocated storage on success, it was not obvious whether '*obj' was guaranteed safe on failure, or whether it was left uninitialized. But a future patch wants to guarantee that visit_type_FOO() does not leak a partially- constructed obj back to the caller; it is easier to implement this if we can reliably state that input visitors assign '*obj' regardless of success or failure, and that on failure *obj is NULL. Add assertions to enforce consistency in the final setting of err vs. *obj. The opts-visitor start_struct() doesn't set an error, but it also was doing a weird check for 0 size; all callers pass in non-zero size if obj is non-NULL. The testsuite has at least one spot where we no longer need to pre-initialize a variable prior to a visit; valgrind confirms that the test is still fine with the cleanup. A later patch will document the design constraint implemented here. Signed-off-by: Eric Blake --- v15: enhance commit message, hoist assertions from later in series v14: no change v13: no change v12: new patch --- qapi/qapi-visit-core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 3a131ce..7ad5ff4 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -27,7 +27,7 @@ void visit_start_struct(Visitor *v, const char *name, void **obj, v->start_struct(v, name, obj, size, &err); if (obj && v->type == VISITOR_INPUT) { - assert(err || *obj); + assert(!err != !*obj); } error_propagate(errp, err); } @@ -62,11 +62,11 @@ void visit_start_alternate(Visitor *v, const char *name, assert(obj && size >= sizeof(GenericAlternate)); if (v->start_alternate) { v->start_alternate(v, name, obj, size, promote_int, &err); - if (v->type == VISITOR_INPUT) { - assert(err || *obj); - } - error_propagate(errp, err); } + if (v->type == VISITOR_INPUT) { + assert(!err != !*obj); + } + error_propagate(errp, err); } void visit_end_alternate(Visitor *v) @@ -205,7 +205,7 @@ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp) assert(obj); v->type_str(v, name, obj, &err); if (v->type == VISITOR_INPUT) { - assert(err || *obj); + assert(!err != !*obj); } error_propagate(errp, err); } @@ -223,7 +223,7 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) assert(obj); v->type_any(v, name, obj, &err); if (v->type == VISITOR_INPUT) { - assert(err || *obj); + assert(!err != !*obj); } error_propagate(errp, err); }