=== modified file 'driver-csi.c' --- driver-csi.c 2017-03-29 19:26:44 +0000 +++ driver-csi.c 2012-11-30 16:34:47 +0000 @@ -644,29 +644,23 @@ TermKeyCsi *csi = info; - switch(CHARAT(0)) { - case 0x1b: - if(tk->buffcount < 2) - return TERMKEY_RES_NONE; - - switch(CHARAT(1)) { - case 0x4f: // ESC-prefixed SS3 - return peekkey_ss3(tk, csi, 2, key, force, nbytep); - - case 0x5b: // ESC-prefixed CSI - return peekkey_csi(tk, csi, 2, key, force, nbytep); - } - - return TERMKEY_RES_NONE; - - case 0x8f: // SS3 - return peekkey_ss3(tk, csi, 1, key, force, nbytep); - - case 0x9b: // CSI - return peekkey_csi(tk, csi, 1, key, force, nbytep); - } - - return TERMKEY_RES_NONE; + // Now we're sure at least 1 byte is valid + unsigned char b0 = CHARAT(0); + + if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == '[') { + return peekkey_csi(tk, csi, 2, key, force, nbytep); + } + else if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == 'O') { + return peekkey_ss3(tk, csi, 2, key, force, nbytep); + } + else if(b0 == 0x8f) { + return peekkey_ss3(tk, csi, 1, key, force, nbytep); + } + else if(b0 == 0x9b) { + return peekkey_csi(tk, csi, 1, key, force, nbytep); + } + else + return TERMKEY_RES_NONE; } struct TermKeyDriver termkey_driver_csi = {