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.
This commit is contained in:
Craig Barnes 2021-06-08 16:52:00 +01:00
parent b34d76f711
commit 620fe8e764

27
vt.c
View file

@ -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;