From patchwork Mon Mar 25 13:15:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15594 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 B6BE423E00 for ; Mon, 25 Mar 2013 13:15:21 +0000 (UTC) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by fiordland.canonical.com (Postfix) with ESMTP id 8B06CA193A1 for ; Mon, 25 Mar 2013 13:15:21 +0000 (UTC) Received: by mail-la0-f47.google.com with SMTP id fj20so11208360lab.20 for ; Mon, 25 Mar 2013 06:15:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=xo0TYDwhG4XtuFv9bSHog1ErX4m+MiB3s4YMx3Mlhjs=; b=GnDpNBUctdU+yAD0TI+DOaqb6EUOXXyaKZR/GsFLgAgRyamGBSvM0ceUw2kQTl/ptU ajERKv0L4dZSJVpnX62nPWPjB54jnxVj2WNi5wKokFHpIUGK/HMDmhBHmWvRdzAEdIfy yZwK188lhStdOd1F601KxHNb6qh9KhRIywyMhgYdQRGujko/pm1BFt2u0qLi+X0rt+Bc iJ1+iY3x5u9rzN9H2amoSUGx50zXSCR5DinArNr+pCmDcM4RFL5V8ZXK021QnV2vB5Pa kPtPFsm6xtXuHeZJaTwUGrbW3jnLxct1m3XNXSG2Zs6AMJ2KV7KK1IJ0kmMlrKroYv75 /gIQ== X-Received: by 10.152.105.38 with SMTP id gj6mr5989005lab.25.1364217321111; Mon, 25 Mar 2013 06:15:21 -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.112.147.5 with SMTP id tg5csp47204lbb; Mon, 25 Mar 2013 06:15:20 -0700 (PDT) X-Received: by 10.204.109.14 with SMTP id h14mr5464322bkp.39.1364217318783; Mon, 25 Mar 2013 06:15:18 -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 ha14si3796703bkc.41.2013.03.25.06.15.18 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Mar 2013 06:15:18 -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 1UK7F4-0001vp-AI; Mon, 25 Mar 2013 13:15:14 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Paolo Bonzini , Anthony Liguori Subject: [PATCH v7 1/2] qom: Detect attempts to add a property that already exists Date: Mon, 25 Mar 2013 13:15:13 +0000 Message-Id: <1364217314-7400-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1364217314-7400-1-git-send-email-peter.maydell@linaro.org> References: <1364217314-7400-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQmUv6NwF8FX7v1BEExU4r7Os3+qlmGxrPhVAmGzpRnftVDxJiJ4aAZ2YABGxkjizjXc8ENF Detect attempts to add a property to an object if one of that name already exists, and report them as errors. Signed-off-by: Peter Maydell Reviewed-by: Anthony Liguori Acked-by: Paolo Bonzini --- qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index 3d638ff..3f77968 100644 --- a/qom/object.c +++ b/qom/object.c @@ -629,7 +629,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) { + error_setg(errp, "attempt to add duplicate property '%s'" + " to object (type '%s')", name, + object_get_typename(obj)); + return; + } + } + + prop = g_malloc0(sizeof(*prop)); prop->name = g_strdup(name); prop->type = g_strdup(type);