fix UB in vtparse

closes: #1631
This commit is contained in:
Wez Furlong committed 2022-02-10 08:20:22 -07:00
1 parent 3316695dc0
commit 41342ef740
2 files changed
+17 -4

No files matched your search

+11 -2
View File
@@ -29,12 +29,21 @@ fn lookup(state: State, b: u8) -> (Action, State) {
}
#[inline(always)]
#[cfg(not(test))]
fn lookup_entry(state: State) -> Action {
unsafe { *ENTRY.get_unchecked(state as usize) }
}
#[inline(always)]
#[cfg(debug_assertions)]
#[cfg(test)]
fn lookup_entry(state: State) -> Action {
*ENTRY
.get(state as usize)
.unwrap_or_else(|| panic!("State {:?} has no entry in ENTRY", state))
}
#[inline(always)]
#[cfg(test)]
fn lookup_exit(state: State) -> Action {
*EXIT
.get(state as usize)
@@ -42,7 +51,7 @@ fn lookup_exit(state: State) -> Action {
}
#[inline(always)]
#[cfg(not(debug_assertions))]
#[cfg(not(test))]
fn lookup_exit(state: State) -> Action {
unsafe { *EXIT.get_unchecked(state as usize) }
}
+6 -2
View File
@@ -308,7 +308,7 @@ pub(crate) static TRANSITIONS: [[u16; 256]; 15] = [
define_table!(apc_string),
];
pub(crate) static ENTRY: [Action; 15] = [
pub(crate) static ENTRY: [Action; 17] = [
Action::None, // Ground
Action::Clear, // Escape
Action::None, // EscapeIntermediate
@@ -324,9 +324,11 @@ pub(crate) static ENTRY: [Action; 15] = [
Action::OscStart, // OscString
Action::None, // SosPmString
Action::ApcStart, // ApcString
Action::None, // Anywhere
Action::None, // Utf8Sequence
];
pub(crate) static EXIT: [Action; 15] = [
pub(crate) static EXIT: [Action; 17] = [
Action::None, // Ground
Action::None, // Escape
Action::None, // EscapeIntermediate
@@ -342,6 +344,8 @@ pub(crate) static EXIT: [Action; 15] = [
Action::OscEnd, // OscString
Action::None, // SosPmString
Action::ApcEnd, // ApcString
Action::None, // Anywhere
Action::None, // Utf8Sequence
];
#[cfg(test)]