tweaks: avoid using strlen() where it is not needed

This commit is contained in:
Benno Schulenberg 2019-12-12 11:45:15 +01:00
parent 3251a216cd
commit 772f1029e5
2 changed files with 5 additions and 5 deletions

View File

@ -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;

View File

@ -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"));