Skip to content

Commit 6165346

Browse files
committed
Reorder and add an assert
1 parent 9fdc3aa commit 6165346

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/sdl2/audio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,19 +1012,19 @@ impl AudioCVT {
10121012
if self.raw.needed != 0 {
10131013
let mut raw = self.raw;
10141014

1015-
// calculate the size of the dst buffer.
1016-
use std::convert::TryInto;
1017-
raw.len = src.len().try_into().expect("Buffer length overflow");
1018-
1015+
// Calculate the size of the buffer we're handing to to SDL.
10191016
// This is more a suggestion, and not really a guarantee...
10201017
let dst_size = self.capacity(src.len());
10211018

10221019
// Bounce into SDL2 heap allocation as SDL_ConvertAudio may rewrite the pointer.
10231020
raw.buf = sys::SDL_malloc(dst_size as _) as *mut _;
1021+
use std::convert::TryInto;
1022+
raw.len = src.len().try_into().expect("Buffer length overflow");
10241023
if raw.buf.is_null() {
10251024
panic!("Failed SDL_malloc needed for SDL_ConvertAudio");
10261025
}
10271026
// raw.buf is dst_size long, but we want to copy into only the first src.len bytes.
1027+
assert!(src.len() < dst_size);
10281028
std::slice::from_raw_parts_mut(raw.buf, src.len()).copy_from_slice(src.as_ref());
10291029

10301030
let ret = sys::SDL_ConvertAudio(&mut raw);

0 commit comments

Comments
 (0)