diff mbox

[v6,1/2] qom: Detect attempts to add a property that already exists

Message ID 1363451962-25952-2-git-send-email-peter.maydell@linaro.org
State Superseded
Headers show

Commit Message

Peter Maydell March 16, 2013, 4:39 p.m. UTC
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 <peter.maydell@linaro.org>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
---
 qom/object.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Andreas Färber March 18, 2013, 2:39 p.m. UTC | #1
Am 16.03.2013 17:39, schrieb Peter Maydell:
> 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 <peter.maydell@linaro.org>
> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  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,

No \n in error_setg(), there was a recent cleanup series.

Andreas

> +                       object_get_typename(obj));
> +            return;
> +        }
> +    }
> +
> +    prop = g_malloc0(sizeof(*prop));
>  
>      prop->name = g_strdup(name);
>      prop->type = g_strdup(type);
>
diff mbox

Patch

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);