From 620fe8e76427a3cc5783c0e632a395c9b9752c43 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Tue, 8 Jun 2021 16:52:00 +0100 Subject: [PATCH] vt: fix buggy chains of ternary expressions in action_esc_dispatch() Only the first character in the chain was being compared with `priv` and the rest were just being evaluated as simple expressions. This was causing the G2 and G3 operations to erroneously use the G1 index. Since the characters are a contiguous range, we can just subtract the start of the range to get the appropriate index. The outer switch statement already ensures the values are in range. --- vt.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/vt.c b/vt.c index fc6f8749..d0d215f1 100644 --- a/vt.c +++ b/vt.c @@ -442,32 +442,23 @@ action_esc_dispatch(struct terminal *term, uint8_t final) } break; /* private[0] == 0 */ - case '(': - case ')': - case '*': - case '+': + // Designate character set + case '(': // G0 + case ')': // G1 + case '*': // G2 + case '+': // G3 switch (final) { case '0': { - char priv = term->vt.private; - ssize_t idx = priv == - '(' ? 0 : - ')' ? 1 : - '*' ? 2 : - '+' ? 3 : -1; - xassert(idx != -1); + size_t idx = term->vt.private - '('; + xassert(idx <= 3); term->charsets.set[idx] = CHARSET_GRAPHIC; term_update_ascii_printer(term); break; } case 'B': { - char priv = term->vt.private; - ssize_t idx = priv == - '(' ? 0 : - ')' ? 1 : - '*' ? 2 : - '+' ? 3 : -1; - xassert(idx != -1); + size_t idx = term->vt.private - '('; + xassert(idx <= 3); term->charsets.set[idx] = CHARSET_ASCII; term_update_ascii_printer(term); break;