]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
play: Simplify and improve get_key_map_seq().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 25 Jun 2023 12:29:07 +0000 (14:29 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 18 May 2024 20:03:59 +0000 (22:03 +0200)
Combine it with get_user_key_map_seq() and replace the NULL check
with an assertion since the condition can never be true here. This
makes gcc's static analyzer happy, which complained about a possible
NULL pointer dereference.

play.c

diff --git a/play.c b/play.c
index 4ad83a40c2f14b8bdb7eecd5eb796555a25a977e..f04cf842d94f2c42e44c79542498ccd16703c2cb 100644 (file)
--- a/play.c
+++ b/play.c
@@ -570,15 +570,17 @@ static inline char *get_internal_key_map_seq(int key)
        return para_strdup(default_keyseqs[get_internal_key_map_idx(key)]);
 }
 
-static char *get_user_key_map_seq(int key)
+static char *get_key_map_seq(int key)
 {
-       const char *kma = get_user_key_map_arg(key);
-       const char *p = strchr(kma + 1, ':');
+       const char *kma, *p;
        char *result;
        int len;
 
-       if (!p)
-               return NULL;
+       if (is_internal_key(key))
+               return get_internal_key_map_seq(key);
+       kma = get_user_key_map_arg(key);
+       p = strchr(kma + 1, ':');
+       assert(p); /* We checked earlier that kma contains a colon */
        len = p - kma;
        result = alloc(len + 1);
        memcpy(result, kma, len);
@@ -586,12 +588,6 @@ static char *get_user_key_map_seq(int key)
        return result;
 }
 
-static char *get_key_map_seq(int key)
-{
-       return is_internal_key(key)?
-               get_internal_key_map_seq(key) : get_user_key_map_seq(key);
-}
-
 static char *get_key_map_seq_safe(int key)
 {
        const char hex[] = "0123456789abcdef";