Bugfix: Check that ->symbol != NULL before using strcasecmp()

This commit is contained in:
Michael Stapelberg 2011-08-04 21:38:13 +02:00
parent 787dd4059f
commit 4e350664ae

View File

@ -317,29 +317,42 @@ void kill_configerror_nagbar(bool wait_for_it) {
* i3-nagbar. * i3-nagbar.
* *
*/ */
static bool check_for_duplicate_bindings(struct context *context) { static void check_for_duplicate_bindings(struct context *context) {
bool retval = true;
Binding *bind, *current; Binding *bind, *current;
TAILQ_FOREACH(current, bindings, bindings) { TAILQ_FOREACH(current, bindings, bindings) {
bind = TAILQ_FIRST(bindings); TAILQ_FOREACH(bind, bindings, bindings) {
/* test only bindings visited up to current binding */ /* Abort when we reach the current keybinding, only check the
while ((bind != TAILQ_END(bindings)) && (bind != current)) { * bindings before */
/* testing is not case sensitive */ if (bind == current)
if ((strcasecmp(bind->symbol, current->symbol) == 0) && break;
(bind->keycode == current->keycode) &&
(bind->mods == current->mods)) { /* Check if one is using keysym while the other is using bindsym.
context->has_errors = true; * If so, skip. */
fprintf(stderr, "Duplicated keybinding in config file: mod%d with key %s", current->mods, current->symbol); /* XXX: It should be checked at a later place (when translating the
/* if keycode is 0, this is a keysym binding */ * keysym to keycodes) if there are any duplicates */
if (current->keycode != 0) if ((bind->symbol == NULL && current->symbol != NULL) ||
fprintf(stderr, " and keycode %d", current->keycode); (bind->symbol != NULL && current->symbol == NULL))
fprintf(stderr, "\n"); continue;
retval = false;
} /* If bind is NULL, current has to be NULL, too (see above).
bind = TAILQ_NEXT(bind, bindings); * If the keycodes differ, it can't be a duplicate. */
if (bind->symbol != NULL &&
strcasecmp(bind->symbol, current->symbol) != 0)
continue;
/* Check if the keycodes or modifiers are different. If so, they
* can't be duplicate */
if (bind->keycode != current->keycode ||
bind->mods != current->mods)
continue;
context->has_errors = true;
fprintf(stderr, "Duplicated keybinding in config file: mod%d with key %s", current->mods, current->symbol);
/* if keycode is 0, this is a keysym binding */
if (current->keycode != 0)
fprintf(stderr, " and keycode %d", current->keycode);
fprintf(stderr, "\n");
} }
} }
return retval;
} }
void parse_file(const char *f) { void parse_file(const char *f) {