From patchwork Fri Oct 26 17:29:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 12550 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 6EC3223F6F for ; Fri, 26 Oct 2012 17:29:39 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id D6141A183AF for ; Fri, 26 Oct 2012 17:29:38 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so3954680iej.11 for ; Fri, 26 Oct 2012 10:29:38 -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:in-reply-to:references :x-gm-message-state; bh=JqDiAcSS4TqX9z2lpV4iCEu4fQMap3w8o4MFg+Z3mgo=; b=Q7VM3eyRcvqy5Yzy0sUA+89Wnc7aLtFKDGpXRrYPDDSkEERleM4yYiThPXYte+g2/+ 1lGfOeh1SWtlmOyYI2hlLM6fjlql7Xn83/pX6Ullm4+/qwUXCHIO3nc1YAeonQ7pga19 +SSmHP/9REH7pOLhvCqzjGS0i9GNWnW8WThOZmQG+HMBjOjx1tDxfGBsCKexiLh4VxD+ E8dNxg5Wto12wXBEutC0lb5mmRQq1mO6PBiaEAD5tfXBqF/J334z6fSqDSzpBmtfIssy ejnT+l6fNZ3NNJ+GqSjImuG79Yo9S0PV3IHOYM31uIZJL86nIVtS81FRNXyRE+2vMNmC mB5A== Received: by 10.50.140.97 with SMTP id rf1mr2799354igb.70.1351272578430; Fri, 26 Oct 2012 10:29:38 -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.67.148 with SMTP id n20csp285501igt; Fri, 26 Oct 2012 10:29:36 -0700 (PDT) Received: by 10.216.26.138 with SMTP id c10mr14916332wea.76.1351272574879; Fri, 26 Oct 2012 10:29:34 -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 d8si162376wix.14.2012.10.26.10.29.33 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Oct 2012 10:29:34 -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 1TRnir-0003eQ-Ih; Fri, 26 Oct 2012 18:29:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori , Paolo Bonzini Subject: [PATCH v5 1/2] qom: Detect attempts to add a property that already exists Date: Fri, 26 Oct 2012 18:29:28 +0100 Message-Id: <1351272569-14009-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1351272569-14009-1-git-send-email-peter.maydell@linaro.org> References: <1351272569-14009-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQm8BBWtMbrX6iCHsLBOGoHDhhD0oBcusU3bwxRj5zo62knLHr3lp9StS8bQCV8kfWwvUBdq 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 --- qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index e3e9242..a9dfc8c 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) { + error_setg(errp, "attempt to add duplicate property '%s'" + " to object (type '%s')\n", name, + object_get_typename(obj)); + return; + } + } + + prop = g_malloc0(sizeof(*prop)); prop->name = g_strdup(name); prop->type = g_strdup(type);