summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-07-21 23:36:13 +0200
committerPřemysl Janouch <p@janouch.name>2018-07-21 23:36:13 +0200
commit9b38c4c74fd16a5dd39cc340ffdcfd8c9d672442 (patch)
tree95c7cfce8e844419ba96619337297bcd7281c641
parent68c620fdee8dcfc07b9e0eabe2e97ff22af09a86 (diff)
downloadnncmpp-9b38c4c74fd16a5dd39cc340ffdcfd8c9d672442.tar.gz
nncmpp-9b38c4c74fd16a5dd39cc340ffdcfd8c9d672442.tar.xz
nncmpp-9b38c4c74fd16a5dd39cc340ffdcfd8c9d672442.zip
Fix undefined behaviour
-rw-r--r--nncmpp.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/nncmpp.c b/nncmpp.c
index 72d30fd..8751b8e 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -2211,12 +2211,15 @@ app_init_bindings (const char *keymap,
ARRAY (struct binding, a)
ARRAY_INIT_SIZED (a, defaults_len);
+ // Order for stable sorting
+ size_t order = 0;
+
termo_key_t decoded;
for (size_t i = 0; i < defaults_len; i++)
{
hard_assert (!*termo_strpkey_utf8 (g.tk,
defaults[i].key, &decoded, TERMO_FORMAT_ALTISMETA));
- a[a_len++] = (struct binding) { decoded, defaults[i].action, a_len };
+ a[a_len++] = (struct binding) { decoded, defaults[i].action, order++ };
}
struct config_item *root = config_item_get (g.config.root, keymap, NULL);
@@ -2227,7 +2230,7 @@ app_init_bindings (const char *keymap,
int action;
while (app_next_binding (&iter, &decoded, &action))
- a[a_len++] = (struct binding) { decoded, action, a_len };
+ a[a_len++] = (struct binding) { decoded, action, order++ };
}
// Use the helper field to use the last mappings of identical bindings