Avoid copying characters beyond last

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Thu, 11 Oct 2012 19:03:57 +0200

Positions without GLYPH_SET are copied as spaces. This is correct for tabs
and others locate sequences, but is wrong in the end of lines, where you get
a lot of spaces where there isn't any text. This patch avoid these ghost
trailing whitespaces, but still transform tabs into spaces.
---
 st.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/st.c b/st.c
index 8641a7a..532d706 100644
--- a/st.c
+++ b/st.c
_AT_@ -691,7 +691,6 @@ void
 selcopy(void) {
 	char *str, *ptr, *p;
 	int x, y, bufsize, is_selected = 0, size;
-	Glyph *gp;
 
 	if(sel.bx == -1) {
 		str = NULL;
_AT_@ -701,9 +700,11 @@ selcopy(void) {
 
 		/* append every set & selected glyph to the selection */
 		for(y = 0; y < term.row; y++) {
-			for(x = 0; x < term.col; x++) {
-				gp = &term.line[y][x];
+			Glyph *gp = &term.line[y][0], *last = gp + term.col;
 
+			while(--last >= gp && !(last->state & GLYPH_SET))
+				/* nothing */;
+			for(x = 0; gp <= last; x++, ++gp) {
 				if(!(is_selected = selected(x, y)))
 					continue;
 				p = (gp->state & GLYPH_SET) ? gp->c : " ";
-- 
1.7.10.4
--BOKacYhQ+x31HxR3--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 11 2012 - 19:36:04 CEST