From 44153f4aabdd8fd70c26c2e67c40c9531c3d96d8 Mon Sep 17 00:00:00 2001 From: TheAlternateDoctor Date: Tue, 12 Mar 2024 13:28:15 +0100 Subject: [PATCH] Fixed issue with diffs containing non matching edited strings --- src/msbt.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/msbt.rs b/src/msbt.rs index 5e862ea..4d1426b 100644 --- a/src/msbt.rs +++ b/src/msbt.rs @@ -105,9 +105,13 @@ pub fn edit_string_by_label(msbt_strings: &mut [MSBTString],label: String, strin ByteOrder::BigEndian => string.encode_utf16().flat_map(|c| c.to_be_bytes()).collect(), ByteOrder::LittleEndian => string.encode_utf16().flat_map(|c| c.to_le_bytes()).collect(), }; - let vec_index = msbt_strings.iter().position(|s| s.label == label).unwrap(); - let old_index = msbt_strings.get(vec_index).unwrap().index; - msbt_strings[vec_index] = MSBTString{ index: old_index, label, string:new_string }; + match msbt_strings.iter().position(|s| s.label == label){ + Some(index) => { + let old_index = msbt_strings.get(index).unwrap().index; + msbt_strings[index] = MSBTString{ index: old_index, label, string:new_string }; + }, + None => println!("No label named \"{}\" found!", label), + }; }