ref: 2fd35e9bf8077c6a4d2b86d9b456711b18d5f332
parent: b4eb667f02c32f007290b68adc95c8fbd9a2c3cd
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Oct 20 23:42:24 EDT 2018
kbdfs: don't get confused by broken utf8
--- a/sys/src/cmd/aux/kbdfs/kbdfs.c
+++ b/sys/src/cmd/aux/kbdfs/kbdfs.c
@@ -625,23 +625,29 @@
p = buf;
e = buf + sizeof(buf);
while((n = read(consfd, p, e - p)) > 0){
- x = buf + n;
- while(p < x && fullrune(p, x - p)){
+ x = p + n;
+ p = buf;
+ while((n = x - p) > 0){
+ if(!fullrune(p, n)){
+ memmove(buf, p, n);
+ break;
+ }
p += chartorune(&r, p);
- if(r){
- if(r == 021 || r == 023) /* XON/XOFF */
- continue;
- if(r == '\n' && cr){
- cr = 0;
- continue;
- }
- if(cr = (r == '\r'))
- r = '\n';
- send(runechan, &r);
+ if(r == 021 || r == 023) /* XON/XOFF */
+ continue;
+ if(r == 0 || r == Runeerror){
+ cr = 0;
+ continue;
}
+ if(r == '\n' && cr){
+ cr = 0;
+ continue;
+ }
+ if(cr = (r == '\r'))
+ r = '\n';
+ send(runechan, &r);
}
- n = x - p;
- memmove(buf, p, n);
+ if(n < 0) n = 0;
p = buf + n;
}