Received: from eggs.gnu.org ([208.118.235.92]:34779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGuBf-0001br-FV for qemu-devel@nongnu.org; Sat, 16 Mar 2013 12:42:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGuBd-0006H7-1c for qemu-devel@nongnu.org; Sat, 16 Mar 2013 12:42:27 -0400 Received: from 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]:32975 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGuBc-0006H1-Rl for qemu-devel@nongnu.org; Sat, 16 Mar 2013 12:42:24 -0400 From: Peter Maydell Date: Sat, 16 Mar 2013 16:39:21 +0000 Message-Id: <1363451962-25952-2-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1363451962-25952-1-git-send-email-peter.maydell@linaro.org> References: <1363451962-25952-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH v6 1/2] qom: Detect attempts to add a property that already exists List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Anthony Liguori , patches@linaro.org 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); -- 1.7.9.5