diff options
| author | Furkan Sahin <furkansahin824@proton.me> | 2024-09-15 19:16:59 -0500 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2025-05-08 14:10:14 -0400 |
| commit | 60b74d65d60a791864065f39eb96fe250a98e22e (patch) | |
| tree | 3c61d35e38624e6a5b8969d48c26183981666cef | |
| parent | 060c842a6498a75e1f653fe9b5e0da7c057daba1 (diff) | |
formattingbindsym-tocode-cartesian
| -rw-r--r-- | sway/commands/bind.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 01e7cda0..e907d9bf 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -469,7 +469,8 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv, // translate keysyms into keycodes if (!translate_binding(binding)) { - sway_log(SWAY_INFO,"Unable to translate bindsym into bindcode: %s", argv[0]); + sway_log(SWAY_INFO, + "Unable to translate bindsym into bindcode: %s", argv[0]); } list_t *mode_bindings; @@ -725,6 +726,10 @@ bool translate_binding(struct sway_binding *binding) { int num_syms = binding->keys->length; list_t **sym2code = malloc(num_syms * sizeof(list_t*)); + if (!sym2code) { + sway_log(SWAY_ERROR, + "Unable to allocate memory for symbol:keycode map"); + } // Collect all keycodes for all keysyms for (int i = 0; i < num_syms; i++) { struct keycode_matches matches = { @@ -738,14 +743,19 @@ bool translate_binding(struct sway_binding *binding) { add_matching_keycodes, &matches); if (matches.error) { - sway_log(SWAY_ERROR, "Failed to allocate memory for keycodes while iterating for keysym %" PRIu32, *matches.keysym); - goto error; + sway_log(SWAY_ERROR, + "Failed to allocate memory for keycodes while " + "iterating for keysym %" PRIu32, + *matches.keysym); + goto error; } if (matches.keycodes->length == 0) { - sway_log(SWAY_INFO, "Unable to convert keysym %" PRIu32 " into" - "any keycodes", *matches.keysym); - goto error; + sway_log(SWAY_INFO, + "Unable to convert keysym %" PRIu32 " into" + "any keycodes", + *matches.keysym); + goto error; } sym2code[i] = matches.keycodes; @@ -755,14 +765,18 @@ bool translate_binding(struct sway_binding *binding) { xkb_keycode_t **combos = cartesian_product(sym2code, num_syms); for (int i = 0; i < num_syms; i++) { - struct sway_binding * copy_binding = malloc(sizeof(struct sway_binding)); + struct sway_binding *copy_binding = malloc(sizeof(*copy_binding)); binding->type = BINDING_KEYCODE; *copy_binding = *binding; list_t *keys = create_list(); // copy the keys over for (int j = 0; j < num_syms; j++) { - xkb_keycode_t * key = malloc(sizeof(xkb_keycode_t)); + xkb_keycode_t *key = malloc(sizeof(*key)); + if (!key) { + sway_log(SWAY_ERROR, + "Unable to allocate memory for key when translating"); + } *key = combos[i][j]; list_add(keys, key); } |
