From: Jose Dapena Paz Date: Fri, 8 May 2009 09:40:07 +0000 (+0200) Subject: Fix crash when we hit the editor limit of an utf8 formated text on replying. X-Git-Tag: 3.0.17-rc3~2 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=1d8c1d3178b563be1a55c2d7004538618f63d995 Fix crash when we hit the editor limit of an utf8 formated text on replying. * src/widgets/modest-msg-edit-window.c (body_insert_text): use utf8 for counting characters on controlling the limit of characters in a message in modest (fixes NB#115353). --- diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index c6a998e..51e2160 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -3542,28 +3542,33 @@ body_insert_text (GtkTextBuffer *buffer, { GtkTextIter end_iter; gint offset; + glong utf8_len; gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end_iter); offset = gtk_text_iter_get_offset (&end_iter); + utf8_len = g_utf8_strlen (text, len); - if (offset + len > MAX_BODY_LENGTH) { + if (offset + utf8_len > MAX_BODY_LENGTH) { g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text"); if (offset < MAX_BODY_LENGTH) { gchar *result; + gchar *utf8_end; + + utf8_end = g_utf8_offset_to_pointer (text, MAX_BODY_LENGTH - offset); /* Prevent endless recursion */ - result = g_strndup (text, MAX_BODY_LENGTH - offset); + result = g_strndup (text, utf8_end - text); g_signal_handlers_block_by_func (G_OBJECT (buffer), G_CALLBACK (body_insert_text), window); g_signal_emit_by_name (G_OBJECT (buffer), "insert-text", location, - (gpointer) result, (gpointer) MAX_BODY_LENGTH - offset, + (gpointer) result, (gpointer) (utf8_end - text), (gpointer) window); g_signal_handlers_unblock_by_func (G_OBJECT (buffer), G_CALLBACK (body_insert_text), window); } } - if (offset + len > MAX_BODY_LENGTH) { + if (offset + utf8_len > MAX_BODY_LENGTH) { hildon_banner_show_information (GTK_WIDGET (window), NULL, _CS("ckdg_ib_maximum_characters_reached")); }