diff options
author | Alban Crequy <alban.crequy@collabora.co.uk> | 2011-12-07 16:50:02 +0000 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-12-13 10:11:22 +0000 |
commit | b0a398bc4f75bf86e4e4df171df79b52e9fd3503 (patch) | |
tree | 171d05ea22081112d3427d5302a0871da9304247 | |
parent | 1cb38f6d3ceba586e3a98be285f172fc8448becd (diff) |
dataforms: fix crash in add_field_to_node_using_default()
field->raw_value_contents was not initialized when the field was not coming
from a WockyNode. It leads to a segfault in add_field_to_node_using_default().
The following code was triggering the crash:
form = g_object_new (WOCKY_TYPE_DATA_FORM, NULL);
wocky_data_form_set_string (form, "field", "value", TRUE);
wocky_data_form_add_to_node (form, ...);
This patch initializes field->raw_value_contents when the WockyNode is created
through data_form_set_value().
The unit tests are updated to check this.
https://bugs.freedesktop.org/show_bug.cgi?id=43584
-rw-r--r-- | wocky/wocky-data-form.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/wocky/wocky-data-form.c b/wocky/wocky-data-form.c index 16b7100..6856b52 100644 --- a/wocky/wocky-data-form.c +++ b/wocky/wocky-data-form.c @@ -687,6 +687,7 @@ data_form_set_value (WockyDataForm *self, gboolean create_if_missing) { WockyDataFormField *field; + GType t; g_return_val_if_fail (field_name != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); @@ -714,6 +715,35 @@ data_form_set_value (WockyDataForm *self, wocky_g_value_slice_free (field->value); field->value = value; + + g_strfreev (field->raw_value_contents); + + t = G_VALUE_TYPE (field->value); + if (t == G_TYPE_STRING) + { + const gchar const *value_str[] = + { g_value_get_string (field->value), NULL }; + + field->raw_value_contents = g_strdupv ((GStrv) value_str); + } + else if (t == G_TYPE_BOOLEAN) + { + const gchar const *value_str[] = + { g_value_get_boolean (field->value) ? "1" : "0", NULL }; + + field->raw_value_contents = g_strdupv ((GStrv) value_str); + } + else if (t == G_TYPE_STRV) + { + const GStrv value_str = g_value_get_boxed (field->value); + + field->raw_value_contents = g_strdupv (value_str); + } + else + { + g_assert_not_reached (); + } + return TRUE; } @@ -1034,6 +1064,7 @@ add_field_to_node_using_default (WockyDataFormField *field, wocky_node_set_attribute (field_node, "type", type_to_str (field->type)); + g_assert (field->raw_value_contents != NULL); for (s = field->raw_value_contents; *s != NULL; s++) wocky_node_add_child_with_content (field_node, "value", *s); } |