Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: fix ancient bug with empty lines



On 8 Nov, I wrote:
> It is still broken for yy. This is a separate problem: we want to cut
> zero bytes but set CUTBUFFER_LINE. I'm not sure how to fix that exactly.

This did work in 3.0 too, though I'll admit it's not entirely useful.
It stems in part from 13767 which tries to avoid doing an alloc of
0 bytes. Are there any thoughts on this patch which makes it allocate 1
byte. zalloc does much the same.

We still separately block attempts to do yy, dd, cc etc on a completely
empty buffer. I'm not inclined to do anything about that.

Oliver


diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 03a2bdc..f56063e 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -916,7 +916,7 @@ cut(int i, int ct, int flags)
 void
 cuttext(ZLE_STRING_T line, int ct, int flags)
 {
-    if (!ct || zmod.flags & MOD_NULL)
+    if (!(ct || vilinerange) ||  zmod.flags & MOD_NULL)
 	return;
 
     UNMETACHECK();
@@ -989,8 +989,9 @@ cuttext(ZLE_STRING_T line, int ct, int flags)
 	cutbuf.buf = s;
 	cutbuf.len += ct;
     } else {
+	/* don't alloc 0 bytes; length 0 occurs for blank lines in vi mode */
 	cutbuf.buf = realloc((char *)cutbuf.buf,
-			     (cutbuf.len + ct) * ZLE_CHAR_SIZE);
+			     (cutbuf.len + (ct ? ct : 1)) * ZLE_CHAR_SIZE);
 	ZS_memcpy(cutbuf.buf + cutbuf.len, line, ct);
 	cutbuf.len += ct;
     }
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index 7e5385b..4b9c4d9 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -30,6 +30,13 @@
 >BUFFER: one
 >CURSOR: 0
 
+  zletest $'1\eo\eyya2\epa3'
+0:yank and paste blank line
+>BUFFER: 1
+>2
+>3
+>CURSOR: 5
+
   zletest $' four\eO\C-v\tthree\eO  two\eOone\e3J'
 0:join lines with line count
 >BUFFER: one two three



Messages sorted by: Reverse Date, Date, Thread, Author