From patchwork Fri Sep 7 13:55:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11253 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 41A2123F25 for ; Fri, 7 Sep 2012 13:55:55 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id F15FAA18E35 for ; Fri, 7 Sep 2012 13:55:54 +0000 (UTC) Received: by iafj25 with SMTP id j25so2986402iaf.11 for ; Fri, 07 Sep 2012 06:55:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=eUjbE+ERM64NaeK/4D/XEPy1fXVlIiTRMK0/7Ccz3Vc=; b=S7RqNJ9bU2Ee+HQQmA++dZ4+LTWjo8XMrAgDu2cElgYyclZM/dE4epchXkcXIT+62X A8pDYJLfYPDMf80VArz4mpjoIUKVuV+HZwyDr02XAOgs6msdrxZTId48w6yIckb3GlAf VkQEFo0dpoV6fYA3ps7QvcflD/eZaE7eglZw5p06Lo4wRlGqj/Rvkr9Qqnk/rwZh47n2 n/qQOy+E9mjbdaNPiCIBdYsvTIQmhYvSTKzuOI3pYwB5gBgCMzMan3SogyNiUdlT0NSX swgVin1Pkc6fBx3AbGn0CH6FI2wUxYo+KMTB27eHuEdYueRijUfu61CjfVks9UXQy5y4 jeEg== Received: by 10.42.60.139 with SMTP id q11mr7064548ich.53.1347026154353; Fri, 07 Sep 2012 06:55:54 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp381228igc; Fri, 7 Sep 2012 06:55:53 -0700 (PDT) Received: by 10.180.19.166 with SMTP id g6mr12490669wie.13.1347026152099; Fri, 07 Sep 2012 06:55:52 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id l62si7008985wei.98.2012.09.07.06.55.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 07 Sep 2012 06:55:52 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1T9z28-0003vx-AU; Fri, 07 Sep 2012 14:55:44 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori , Paolo Bonzini , Markus Armbruster Subject: [PATCH v2] qom: Reject attempts to add a property that already exists Date: Fri, 7 Sep 2012 14:55:44 +0100 Message-Id: <1347026144-15098-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQlHd31dCz96MoW0gj6wBZ9S6Rj1SUbNRjseDWtjIGVyH0EjHdwtWfYG1QXN3Wx1jC0h34Dh Reject attempts to add a property to an object if one of that name already exists. This is always a bug in the caller; this is merely diagnosing it gracefully rather than behaving oddly later. Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber --- Changes v1->v2: * use abort() rather than assert(0), as suggested by Paolo * make the diagnostic message a little more helpful by including the type name, and adding '' around names * the patches fixing bugs which this patch makes fatal errors have both now been committed to master, so there's no barrier to committing it now qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index e3e9242..3da4c0e 100644 --- a/qom/object.c +++ b/qom/object.c @@ -620,7 +620,18 @@ void object_property_add(Object *obj, const char *name, const char *type, ObjectPropertyRelease *release, void *opaque, Error **errp) { - ObjectProperty *prop = g_malloc0(sizeof(*prop)); + ObjectProperty *prop; + + QTAILQ_FOREACH(prop, &obj->properties, node) { + if (strcmp(prop->name, name) == 0) { + /* This is always a bug in the caller */ + fprintf(stderr, "attempt to add duplicate property '%s'" + " to object (type '%s')\n", name, object_get_typename(obj)); + abort(); + } + } + + prop = g_malloc0(sizeof(*prop)); prop->name = g_strdup(name); prop->type = g_strdup(type);