Hash :e153bd83 Author : Date :
2014-01-06T11:04:02
Fix escape sequence processing when only one byte available
The read call in the escape sequence processing does not
handle the case where only the first byte is available. This can
happen for example on a slow serial terminal.
Comment by @antirez:
I reworked the code for brevity, for historical reasons here is the
proposed patch. I believe my fix should be functionally equivalent.
Original fix:
case 27: /* escape sequence */
/* Read the next two bytes representing the
escape sequence. */
- if (read(fd,seq,2) == -1) break;
+ {
+ ssize_t b = read(fd, seq, 2);
+
+ if (b < 0) break;
+
+ if (b == 1) {
+ b = read(fd,&seq[1], 1);
+ if (b != 1) {
+ break;
+ }
+ }
+ }
See PR #47.