diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2021-06-08 15:52:00 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2021-06-08 15:52:00 +0000 |
| commit | 620fe8e76427a3cc5783c0e632a395c9b9752c43 (patch) | |
| tree | 851b7caf8ec9d02d882cd96d7cb743c437c058bc | |
| parent | terminal: fix compilation error when debug logging is enabled (diff) | |
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.
| -rw-r--r-- | vt.c | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -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; |
