From 06643a441c255dc61728c196bd9ba0416e3633d6 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Sat, 20 May 2017 20:38:59 -0700 Subject: [PATCH] Pass null pointer on empty decode input, for packet loss Although this does not change behavior in the current implementation, which also accepts a length of zero to mean packet loss, the documentation only indicates that a null pointer means packet loss. For future safety, pass a null pointer when the packet is empty. --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2ed9fca..307ab4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -384,8 +384,12 @@ impl Decoder { /// Decode an Opus packet. pub fn decode(&mut self, input: &[u8], output: &mut [i16], fec: bool) -> Result { + let ptr = match input.len() { + 0 => std::ptr::null(), + _ => input.as_ptr(), + }; let len = ffi!(opus_decode, self.ptr, - input.as_ptr(), len(input), + ptr, len(input), output.as_mut_ptr(), len(output) / self.channels as c_int, fec as c_int); Ok(len as usize) @@ -393,8 +397,12 @@ impl Decoder { /// Decode an Opus packet with floating point output. pub fn decode_float(&mut self, input: &[u8], output: &mut [f32], fec: bool) -> Result { + let ptr = match input.len() { + 0 => std::ptr::null(), + _ => input.as_ptr(), + }; let len = ffi!(opus_decode_float, self.ptr, - input.as_ptr(), len(input), + ptr, len(input), output.as_mut_ptr(), len(output) / self.channels as c_int, fec as c_int); Ok(len as usize)