From 91a0d57e92b77279606324b972c23750fc5239c2 Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Thu, 6 Oct 2022 02:03:04 -0400 Subject: [PATCH] fix the no-cap case of `get_terminfo_string` a negative string offset indicates the corresponding cap is not supported on that terminal. return an empty string in this case. previously we'd return garbage. for a test case, observe what happens when fetching `smcup` on `TERM=linux`. --- termbox.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/termbox.h b/termbox.h index 79ddd1d..febf364 100644 --- a/termbox.h +++ b/termbox.h @@ -2439,6 +2439,10 @@ static const char *get_terminfo_string(int16_t str_offsets_pos, const int16_t *str_offset = (int16_t *)(global.terminfo + (int)str_offsets_pos + ((int)str_index * (int)sizeof(int16_t))); + if (*str_offset < 0) { + // A negative indicates the cap is absent from this terminal + return ""; + } if (*str_offset >= str_table_len) { // Invalid string offset return NULL; -- 2.39.5