diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c index 8967c3a0d916..f40ebbfb87de 100644 --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -217,7 +217,8 @@ static int vc_selection_store_chars(struct vc_data *vc, bool unicode) unless non-space at end of line. */ if (obp != bp) { bp = obp; - *bp++ = '\r'; + if ((i + 2) < vc_sel.end) /* Don't add \r to the last line. */ + *bp++ = '\r'; } obp = bp; } @@ -263,6 +264,11 @@ static int vc_do_selection(struct vc_data *vc, unsigned short mode, int ps, new_sel_start = rounddown(ps, vc->vc_size_row); new_sel_end = rounddown(pe, vc->vc_size_row) + vc->vc_size_row - 2; + while ((new_sel_end > pe) + && (is_space_on_vt (sel_pos (new_sel_end, unicode)))) + new_sel_end -= 2; + if (!((new_sel_end) % vc->vc_size_row)) + new_sel_end += 2; break; case TIOCL_SELPOINTER: highlight_pointer(pe);