terminal: parse table needs to have room for all chars

This commit is contained in:
Mitchell Hashimoto
2022-12-14 21:10:22 -08:00
parent 36c6e95dfc
commit 4a3e2b35b9
2 changed files with 7 additions and 4 deletions

View File

@ -245,7 +245,10 @@ pub fn next(self: *Parser, c: u8) [3]?Action {
// In debug mode, we log bad state transitions.
if (builtin.mode == .Debug) {
if (next_state == .anywhere) {
log.warn("state transition to 'anywhere', likely bug: {x}", .{c});
log.debug(
"state transition to 'anywhere' from '{}', likely binary input: {x}",
.{ self.state, c },
);
}
}

View File

@ -38,7 +38,7 @@ fn genTableType() type {
const max_u8 = std.math.maxInt(u8);
const stateInfo = @typeInfo(State);
const max_state = stateInfo.Enum.fields.len;
return [max_u8][max_state]Transition;
return [max_u8 + 1][max_state]Transition;
}
/// Function to generate the full state transition table for VT emulation.
@ -47,9 +47,9 @@ fn genTable() Table {
var result: Table = undefined;
// Initialize everything so every state transition exists
var i: u8 = 0;
var i: usize = 0;
while (i < result.len) : (i += 1) {
var j: u8 = 0;
var j: usize = 0;
while (j < result[0].len) : (j += 1) {
result[i][j] = transition(.anywhere, .none);
}