From 4cc57bdc4178571c7c296b09d09b8da93c828ead Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 11 Dec 2008 11:49:45 +0000 Subject: [PATCH] Improve the safety checks inside the text setters We should check that the contents of the Text actor are not NULL when computing the offsets in bytes. --- clutter/clutter-text.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 8395266eb..b12ca9697 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -2190,7 +2190,7 @@ clutter_text_set_text (ClutterText *self, g_free (priv->text); priv->text = g_strdup (text); - priv->n_bytes = priv->text ? strlen (priv->text) : 0; + priv->n_bytes = strlen (text); priv->n_chars = len; } else @@ -2211,8 +2211,8 @@ clutter_text_set_text (ClutterText *self, g_free (priv->text); priv->text = g_strdup (text); - priv->n_bytes = priv->text ? strlen (priv->text) : 0; - priv->n_chars = priv->text ? g_utf8_strlen (priv->text, -1) : 0; + priv->n_bytes = strlen (text); + priv->n_chars = g_utf8_strlen (text, -1); } clutter_text_dirty_cache (self); @@ -2221,7 +2221,7 @@ clutter_text_set_text (ClutterText *self, g_signal_emit (self, text_signals[TEXT_CHANGED], 0); - g_object_notify (G_OBJECT (text), "text"); + g_object_notify (G_OBJECT (self), "text"); } PangoLayout * @@ -2663,9 +2663,6 @@ clutter_text_set_cursor_position (ClutterText *self, priv = self->priv; - if (priv->text == NULL) - return; - len = g_utf8_strlen (priv->text, -1); if (position < 0 || position >= len) @@ -2862,14 +2859,15 @@ clutter_text_insert_unichar (ClutterText *self, if (wc == 0) return; - clutter_text_truncate_selection (self, NULL, 0); - priv = self->priv; - g_object_ref (self); - new = g_string_new (priv->text); - pos = offset_to_bytes (priv->text, priv->position); + + if (priv->text) + pos = offset_to_bytes (priv->text, priv->position); + else + pos = 0; + new = g_string_insert_unichar (new, pos, wc); clutter_text_set_text (self, new->str); @@ -2881,8 +2879,6 @@ clutter_text_insert_unichar (ClutterText *self, } g_string_free (new, TRUE); - - g_object_unref (self); } void @@ -2920,6 +2916,9 @@ clutter_text_delete_text (ClutterText *self, priv = self->priv; + if (!priv->text) + return; + if (end_pos == -1) { start_bytes = offset_to_bytes (priv->text,