From 0ec79a40f6ba46e57271beb1a3223922c48fa637 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 16 Oct 2020 13:09:50 -0700 Subject: [PATCH] avoid panic if someone cats a PNG to the terminal --- termwiz/src/escape/osc.rs | 3 ++- vtparse/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/termwiz/src/escape/osc.rs b/termwiz/src/escape/osc.rs index 1313f9d2d..816ec07f2 100644 --- a/termwiz/src/escape/osc.rs +++ b/termwiz/src/escape/osc.rs @@ -261,7 +261,8 @@ impl OperatingSystemCommand { // So, for non-numeric OSCs, we look up the prefix and use that. // This only works if the non-numeric OSC code has length == 1. let osc_code = if !p1str.chars().nth(0).unwrap().is_ascii_digit() && osc.len() == 1 { - OperatingSystemCommandCode::from_code(&p1str[0..1]) + let p1rest: String = p1str.chars().skip(1).collect(); + OperatingSystemCommandCode::from_code(&p1rest) } else { OperatingSystemCommandCode::from_code(&p1str) } diff --git a/vtparse/src/lib.rs b/vtparse/src/lib.rs index 14b8e8a57..e0ac83ca0 100644 --- a/vtparse/src/lib.rs +++ b/vtparse/src/lib.rs @@ -307,7 +307,7 @@ impl OscState { self.full = true; } num => { - self.param_indices[num - 1] = self.buffer.len(); + self.param_indices[num.saturating_sub(1)] = self.buffer.len(); self.num_params += 1; } }