Use has_prefix() instead of strncmp() throughout

This is safer than hardcoded string lengths.
This commit is contained in:
Simon Ser 2025-01-07 13:21:56 +01:00 committed by Kenny Levinsen
parent c55dff95bc
commit 0c60d1581f
19 changed files with 44 additions and 49 deletions

View file

@ -246,7 +246,7 @@ static void workspace_name_from_binding(const struct sway_binding * binding,
}
// If the command is workspace number <name>, isolate the name
if (strncmp(_target, "number ", strlen("number ")) == 0) {
if (has_prefix(_target, "number ")) {
size_t length = strlen(_target) - strlen("number ") + 1;
char *temp = malloc(length);
strncpy(temp, _target + strlen("number "), length - 1);