diff --git a/core/src/backend/audio/decoders.rs b/core/src/backend/audio/decoders.rs index b5c8b1d59..f74db1a6d 100644 --- a/core/src/backend/audio/decoders.rs +++ b/core/src/backend/audio/decoders.rs @@ -306,7 +306,7 @@ impl Iterator for StreamTagReader { self.mp3_samples_buffered += i32::from(num_samples); audio_block = &audio_block[4..]; } - *audio_data = swf_data.to_subslice(audio_block).unwrap(); + *audio_data = swf_data.to_subslice(audio_block); Ok(()) } TagCode::ShowFrame if compression == AudioCompression::Mp3 => { diff --git a/core/src/binary_data.rs b/core/src/binary_data.rs index 9f5560060..a570815ae 100644 --- a/core/src/binary_data.rs +++ b/core/src/binary_data.rs @@ -5,6 +5,6 @@ pub type BinaryData = SwfSlice; impl BinaryData { pub fn from_swf_tag(movie: Arc, tag: &swf::DefineBinaryData) -> Self { - SwfSlice::from(movie).to_subslice(tag.data).unwrap() + SwfSlice::from(movie).to_subslice(tag.data) } } diff --git a/core/src/tag_utils.rs b/core/src/tag_utils.rs index 998457b8c..d9e135cf8 100644 --- a/core/src/tag_utils.rs +++ b/core/src/tag_utils.rs @@ -205,18 +205,18 @@ impl SwfSlice { /// /// This function returns None if the given slice is not a subslice of the /// current slice. - pub fn to_subslice(&self, slice: &[u8]) -> Option { + pub fn to_subslice(&self, slice: &[u8]) -> Self { let self_pval = self.movie.data().as_ptr() as usize; let slice_pval = slice.as_ptr() as usize; if (self_pval + self.start) <= slice_pval && slice_pval < (self_pval + self.end) { - Some(Self { + Self { movie: self.movie.clone(), start: slice_pval - self_pval, end: (slice_pval - self_pval) + slice.len(), - }) + } } else { - None + self.copy_empty() } } @@ -289,7 +289,6 @@ impl SwfSlice { if new_start <= new_end { if let Some(result) = self.movie.data().get(new_start..new_end) { self.to_subslice(result) - .unwrap_or_else(|| self.copy_empty()) } else { self.copy_empty() }