#1495 select error on nonvisible first or last line



When select includes some nonvisible lines, in addition to the lines
visible within the textbuffer window, the first or last line can be wrong.
The top or bottom line's contents may be omitted from the result or
fully included in the result even if it was only partially included.

Select operates this way: User moves pointer to beginning of selection
and depresses left mouse button. Then user moves pointer to end of
selection and releases button, at which time xchat makes a copy of the
selected material. To select more than one window's worth of text, user
moves pointer vertically to just below the bottom margin or above the
top margin, and the text in the window scrolls up or down, respectively.
The top or bottom line, now out of view, is mis-selected: though only a
part of it belongs in the selection, the whole line is either completely
excluded or completely included in the selection.

To reproduce the problem:

1. Join a channel with an existing log of varying-width lines, so as
to test the two- and three-subline case as well as the normal case.
Scroll back a few screensful.

2. Start a selection in the middle of some line. Move the pointer down
to and past the bottom margin, and wait as the screen scrolls up until
the beginning of the selection has scrolled out of sight a few lines.

3. Paste the selection somewhere convenient (I use a "vi foo" window).

4. Note that the beginning of the selection is improperly rendered:
Either its line is missing or completely selected, despite that you
only selected the right-hand portion of it. If you selected a line
with no sublines, it is completely missing. If you selected a line with
sublines, it is present or absent depending on what subline you started
the selection on: If you selected the last subline, it is completely
absent. If you selected a non-last subline, it is completely present.

5. Same as step 2 but move the pointer up to and past the top margin,
and wait as the screen scrolls down until the end of the selection
has scrolled out of sight a few lines. Paste the selection somewhere

6. Note that the last line of the selection is completely missing,
whether single- or multiple-subline, no matter where you began selection
among sublines. Note that even if you begin by selecting an entire line
in this case, the line is completely missing from the selection.

Analysis of the problem:

The root of the problem is lines 1232-1233 in xtext.c function
1232 if (line > xtext->adj->page_size || line < 0)
1233 return 0;

This function receives a window line number from gtk_xtext_find_char()
which may be negative or greater than the page_size, and is, in the
error cases.

The attached patch corrects this bug. This occurs on revision 1475.


  • Richard Hitt

    Richard Hitt - 2010-12-27

    Fix for select error (xtext.c)

  • Richard Hitt

    Richard Hitt - 2010-12-28
  • Richard Hitt

    Richard Hitt - 2010-12-28

    Please use the second patch, P1479xchat, instead of the first. The difference is one line, line 1844, in gtk_xtext_get_word(): local variable int offset is now initialized to 0.

    gtk_xtext_find_char() now doesn't always store at pointer int *off. Other invokers of it initialize the pointed-to int, but gtk_xtext_get_word() did not. It doesn't look like the case could occur there where a garbage value could be used, but out of an abundance of caution I submit this second change, to initialize it.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks