GNOME Bugzilla – Bug 61714
gtk_text_iter_forward_cursor_positions() may return incorrect value
Last modified: 2011-02-04 16:09:32 UTC
If you call gtk_text_iter_forward_cursor_positions(iter, N+k) for a buffer containing N-1 characters, the function moves the iterator to the correct position (N-1) but may return TRUE instead of FALSE. Test case: #include <gtk/gtk.h> void test (gchar* str, int pos, int pos_move); int main (int argc, char** argv) { gtk_init (&argc, &argv); test ("One.", 0, 5); test ("One.", 1, 6); test ("One.", 2, 7); test ("One.", 3, 1); test ("One.", 3, 2); test ("One.", 4, 1); } void test (gchar* str, int pos, int pos_move) { GtkTextIter iter; GtkTextBuffer* buffer; gboolean returns; buffer = gtk_text_buffer_new (NULL); gtk_text_buffer_set_text (buffer, str, strlen (str)); gtk_text_buffer_get_iter_at_offset(buffer, &iter, pos); returns = gtk_text_iter_forward_cursor_positions (&iter, pos_move); printf ("returns = %d\n", returns); } Output: returns = 1 returns = 1 returns = 1 returns = 0 returns = 0 returns = 0 I think that the function should always return FALSE in these cases.
I believe the desired behavior is that a TRUE return indicates that the iterator moved, so I think this is NOTABUG, but I'll let Havoc verify this.
The iteration functions return TRUE if the iterator moved _and_ the iterator is not now on the end iterator. I believe this is just the iterator ending up one past the end iterator. I fixed some similar bugs for motion by line on 10-03. BTW, all test cases should really be run with the env variable setting "GTK_DEBUG=text", which would make this sort of thing crash outright instead of just not working properly. Probably we should run tests both with and without GTK_DEBUG=text in case the debug code changes behavior in some way.
2001-10-23 Havoc Pennington <hp@redhat.com> * gtk/gtktextiter.c (gtk_text_iter_forward_cursor_positions): fix return value, #61714 (Vitaly Tishkov) (gtk_text_iter_backward_sentence_starts): ditto (gtk_text_iter_backward_word_starts): ditto (gtk_text_iter_forward_word_ends): ditto (gtk_text_iter_forward_sentence_ends): ditto (gtk_text_iter_backward_cursor_positions): ditto Thanks for the nice test case, made it easy to fix.