shithub: riscv

Download patch

ref: aa3dd7fd8f1b9409979af8263f06e45505326fc1
parent: a77f6553d88b5cda91e5d0054a64b9f1f9d8e304
author: cinap_lenrek <[email protected]>
date: Wed Sep 26 11:48:57 EDT 2012

libdraw: fix ^W corner case tick == 0 for enter()/eenter()

--- a/sys/src/libdraw/eenter.c
+++ b/sys/src/libdraw/eenter.c
@@ -152,10 +152,12 @@
 			}
 			if(k == Ketb){
 				while(tick > 0){
-					buf[--tick] = 0;
+					tick--;
 					if(tick == 0 || strchr("\t ", buf[tick-1]))
 						break;
 				}
+				if(n > tick)
+					memset(buf+tick, 0, n-tick);
 				n = tick;
 				break;
 			}
--- a/sys/src/libdraw/enter.c
+++ b/sys/src/libdraw/enter.c
@@ -160,10 +160,12 @@
 			}
 			if(k == Ketb){
 				while(tick > 0){
-					buf[--tick] = 0;
+					tick--;
 					if(tick == 0 || strchr("\t ", buf[tick-1]))
 						break;
 				}
+				if(n > tick)
+					memset(buf+tick, 0, n-tick);
 				n = tick;
 				break;
 			}