After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 61714 - gtk_text_iter_forward_cursor_positions() may return incorrect value
gtk_text_iter_forward_cursor_positions() may return incorrect value
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
1.3.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2001-10-04 10:53 UTC by Vitaly Tishkov
Modified: 2011-02-04 16:09 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Vitaly Tishkov 2001-10-04 10:53:15 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.
Comment 1 Owen Taylor 2001-10-08 01:34:37 UTC
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.
Comment 2 Havoc Pennington 2001-10-08 02:12:59 UTC
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.
Comment 3 Havoc Pennington 2001-10-23 19:19:31 UTC
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.