From 80733af0b93cfa75bf2af56c391ee1a2717cbd1e Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Thu, 6 Jul 2023 20:30:14 -0400 Subject: [PATCH] skip empty caps (#57) this slipped under the radar because none of the built-in terms have more than one empty key cap, or an empty string for one of the caps we use in init/shutdown. some terms do of course have multiple empty caps. for example, `xterm-color` is missing `khome`, `kend`, and `kcbt` (back-tab), which leads to adding `""` more than once, which leads to a `TB_ERR_CAP_COLLISION` error on init. other terms don't have caps for hiding and showing the cursor, for example. to avoid these errors, we avoid adding empty caps to the trie, and similarly avoid emitting empty caps. it's kind of hard to add a functional test for this as it gets into testing multiple term envs and terminal emulators which is a bit of a pandora's box. as an alternative, i'm going to do some more manual testing on various terms on my system. --- termbox2.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/termbox2.h b/termbox2.h index 0a90dd9..40bfdb7 100644 --- a/termbox2.h +++ b/termbox2.h @@ -2017,6 +2017,9 @@ static int init_cap_trie(void) { static int cap_trie_add(const char *cap, uint16_t key, uint8_t mod) { struct cap_trie_t *next, *node = &global.cap_trie; size_t i, j; + + if (!cap || strlen(cap) <= 0) return TB_OK; // Nothing to do for empty caps + for (i = 0; cap[i] != '\0'; i++) { char c = cap[i]; next = NULL; @@ -3239,6 +3242,7 @@ static int cellbuf_resize(struct cellbuf_t *c, int w, int h) { } static int bytebuf_puts(struct bytebuf_t *b, const char *str) { + if (!str || strlen(str) <= 0) return TB_OK; // Nothing to do for empty caps return bytebuf_nputs(b, str, (size_t)strlen(str)); } -- 2.39.5