From patchwork Sat Mar 16 16:39:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15389 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 96D7223E2C for ; Sat, 16 Mar 2013 16:39:29 +0000 (UTC) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5624FA1981D for ; Sat, 16 Mar 2013 16:39:29 +0000 (UTC) Received: by mail-ve0-f180.google.com with SMTP id jx10so3414089veb.11 for ; Sat, 16 Mar 2013 09:39:28 -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=HQQMIlGN9IqccEujm7x+NozBcxnKYFjm450Wnu+1g/I=; b=H2XKjn00hOK4V2eYMp6W5m40xPNZRQYgtGFnD0hLHJaSmM61NtgTy5HxbUg7y1aDIC waTuevX57hCMvw5muRRiAXAMgynYkvrDz131DsK7aYZtej3fHssBZUiQSnF4rSwCcD+c pdN+oV2RLIuDR5HVra5YrxvZNkxBRqaIELmAz0clTLtmVEqUv2L2cN6MTpH8bfJbYTSW /i7J/cJ0uAZPWm6uypUfxgQXjoo/GR06XUREdFz5/0PmfU993zufFUNAH8DABGj+TYfr zs3IN4P/X+xBmpxBKJOeMFBnZQqOXwD8iRgkq4QqQEWeU5xp7xnt0DvRgfZb0jJCoFJh Ctrw== X-Received: by 10.220.242.73 with SMTP id lh9mr11892730vcb.49.1363451968838; Sat, 16 Mar 2013 09:39:28 -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.58.127.98 with SMTP id nf2csp168324veb; Sat, 16 Mar 2013 09:39:28 -0700 (PDT) X-Received: by 10.204.184.3 with SMTP id ci3mr4418546bkb.115.1363451965908; Sat, 16 Mar 2013 09:39:25 -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 ha11si3364636bkc.15.2013.03.16.09.39.25 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 16 Mar 2013 09:39:25 -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 1UGu8g-0006l3-Cj; Sat, 16 Mar 2013 16:39:22 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini , Anthony Liguori Subject: [PATCH v6 1/2] qom: Detect attempts to add a property that already exists Date: Sat, 16 Mar 2013 16:39:21 +0000 Message-Id: <1363451962-25952-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1363451962-25952-1-git-send-email-peter.maydell@linaro.org> References: <1363451962-25952-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQl9rEw+fo8yEmCwH1XmWoiepR87q2qsSQEx/Xxxp0Q7CsOw8AmYb8U38fRe7i1zKANKdet/ 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 3d638ff..875315a 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')\n", name, + object_get_typename(obj)); + return; + } + } + + prop = g_malloc0(sizeof(*prop)); prop->name = g_strdup(name); prop->type = g_strdup(type);