From 54852b03711f06c5f24af72de583346922176947 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Mon, 25 Mar 2013 13:15:13 +0000 Subject: [PATCH] qom: Detect attempts to add a property that already exists 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 Message-id: 1364217314-7400-2-git-send-email-peter.maydell@linaro.org Signed-off-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..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); -- 2.7.4