summaryrefslogtreecommitdiffstats
path: root/osdep/getch2.c
diff options
context:
space:
mode:
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>2013-07-25 12:21:22 -0300
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2013-07-25 12:21:22 -0300
commit19b1279bb3322699c3669197aa96deeaa262ee5a (patch)
treebec92b8ea436d88161ba5e4f9b0e70f33c8e1fda /osdep/getch2.c
parent057467f6b33b9f7c942bd2327561b74e738285b7 (diff)
downloadmpv-19b1279bb3322699c3669197aa96deeaa262ee5a.tar.bz2
mpv-19b1279bb3322699c3669197aa96deeaa262ee5a.tar.xz
getch2: Remove unused function, fix possible crash
If we still haven't read the full key from the input but it's regardless a unique match in the database, we could receive a NULL keycode from keys_search (it's not a full match after all) and proceed to use it. Don't disable the keycode matching code if we don't have termcap as we can still match against the hardcoded sequences.
Diffstat (limited to 'osdep/getch2.c')
-rw-r--r--osdep/getch2.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c
index e5752ae235..c19a410252 100644
--- a/osdep/getch2.c
+++ b/osdep/getch2.c
@@ -134,16 +134,6 @@ static keycode_st *keys_search(char *buf, int buflen) {
return NULL;
}
-static keycode_st *keys_get_by_cap(char *cap) {
- for (int i = 0; i < getch2_keys.len; i++) {
- keycode_st *st = &getch2_keys.map[i];
-
- if (strcmp(cap, st->cap) == 0)
- return st;
- }
- return NULL;
-}
-
/* pushes only if there is no duplicate.
important as we only consider keys if the matches are unique. */
static keycode_st* keys_push_once(char *p, int code) {
@@ -374,29 +364,33 @@ bool getch2(struct input_ctx *input_ctx)
switch (state) {
case STATE_INITIAL: {
-#ifdef HAVE_TERMCAP
int match_count = keys_count_matches(&getch2_buf[0], getch2_len);
if (match_count == 1) {
keycode_st *st = keys_search(&getch2_buf[0], getch2_len);
- mp_input_put_key(input_ctx, st->code);
- walk_buf(st->len);
+ if (st) {
+ mp_input_put_key(input_ctx, st->code);
+ walk_buf(st->len);
+ } /* else this is still a partial (but unique) match */
+
+ continue;
} else if (match_count > 1) {
continue; /* need more bytes to disambiguate */
} else {
-#endif
- utf8_len = bstr_parse_utf8_code_length(c);
-
- if (utf8_len > 1) {
- state = STATE_UTF8;
- } else {
- if (utf8_len == 1)
- mp_input_put_key(input_ctx, c);
- walk_buf(getch2_pos);
- }
-#ifdef HAVE_TERMCAP
+ /* backtrack, send as UTF-8 */
+ getch2_pos = 0;
+ c = getch2_buf[0];
}
-#endif
+ utf8_len = bstr_parse_utf8_code_length(c);
+
+ if (utf8_len > 1) {
+ state = STATE_UTF8;
+ } else if (utf8_len == 1) {
+ mp_input_put_key(input_ctx, c);
+ walk_buf(1);
+ } else
+ walk_buf(getch2_pos);
+
break;
}
case STATE_UTF8: {