From 33d6a4e829cf6b67f285541a86499b89d44b8a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Fri, 13 Jan 2017 18:33:29 +0100 Subject: [PATCH] Validate that a binding mode is not defined more than once. (#2633) While defining the same mode usually wouldn't hurt and, in fact, the old behavior allows to split the definition of a binding mode into several blocks, this can lead to user errors where they accidentally define a mode twice and don't understand why the mode behaves a certain way (this has been observed in real life :-)). There's no good usecase for splitting a single binding mode into multiple blocks, thus the new behavior is better. fixes #2615 --- src/bindings.c | 3 ++- src/config_directives.c | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bindings.c b/src/bindings.c index c76e7779..bfec27e1 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -32,8 +32,9 @@ static struct Mode *mode_from_name(const char *name, bool pango_markup) { /* Try to find the mode in the list of modes and return it */ SLIST_FOREACH(mode, &modes, modes) { - if (strcmp(mode->name, name) == 0) + if (strcmp(mode->name, name) == 0) { return mode; + } } /* If the mode was not found, create a new one */ diff --git a/src/config_directives.c b/src/config_directives.c index a260518c..82e1a346 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -126,6 +126,15 @@ CFGFUN(enter_mode, const char *pango_markup, const char *modename) { ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE); exit(1); } + + struct Mode *mode; + SLIST_FOREACH(mode, &modes, modes) { + if (strcmp(mode->name, modename) == 0) { + ELOG("The binding mode with name \"%s\" is defined at least twice.\n", modename); + exit(1); + } + } + DLOG("\t now in mode %s\n", modename); FREE(current_mode); current_mode = sstrdup(modename);