From 772f1029e58494f798d91353de4d1a8a599e0d2d Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 12 Dec 2019 11:45:15 +0100 Subject: [PATCH] tweaks: avoid using strlen() where it is not needed --- src/global.c | 6 +++--- src/rcfile.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/global.c b/src/global.c index 6860145a..c0818f9f 100644 --- a/src/global.c +++ b/src/global.c @@ -492,16 +492,16 @@ int keycode_from_string(const char *keystring) if (strcasecmp(keystring, "^H") == 0) return KEY_BACKSPACE; #endif - if (keystring[1] == '/' && strlen(keystring) == 2) + if (keystring[1] == '/' && keystring[2] == '\0') return 31; - if (keystring[1] <= '_' && strlen(keystring) == 2) + if (keystring[1] <= '_' && keystring[2] == '\0') return keystring[1] - 64; else return -1; } else if (keystring[0] == 'M') { if (strcasecmp(keystring, "M-Space") == 0) return (int)' '; - if (keystring[1] == '-' && strlen(keystring) == 3) + if (keystring[1] == '-' && keystring[3] == '\0') return tolower((unsigned char)keystring[2]); else return -1; diff --git a/src/rcfile.c b/src/rcfile.c index 469c4ce2..00922990 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -419,7 +419,7 @@ void parse_binding(char *ptr, bool dobind) ptr = parse_next_word(ptr); keycopy = copy_of(keyptr); - if (strlen(keycopy) < 2) { + if (keycopy[1] == '\0') { jot_error(N_("Key name is too short")); goto free_things; } @@ -428,7 +428,7 @@ void parse_binding(char *ptr, bool dobind) keycopy[0] = toupper((unsigned char)keycopy[0]); keycopy[1] = toupper((unsigned char)keycopy[1]); if (keycopy[0] == 'M' && keycopy[1] == '-') { - if (strlen(keycopy) > 2) + if (keycopy[2] != '\0') keycopy[2] = toupper((unsigned char)keycopy[2]); else { jot_error(N_("Key name is too short"));