Skip to content

Commit b67abb8

Browse files
committed
Style cleanup
1 parent 9691249 commit b67abb8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/sdl2/audio.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,22 +1010,24 @@ impl AudioCVT {
10101010
//! Certain conversions may cause buffer overflows. See AngryLawyer/rust-sdl2 issue #270.
10111011
unsafe {
10121012
if self.raw.needed != 0 {
1013+
use std::convert::TryInto;
1014+
use std::slice::from_raw_parts_mut;
1015+
10131016
let mut raw = self.raw;
10141017

1015-
// Calculate the size of the buffer we're handing to to SDL.
1018+
// Calculate the size of the buffer we're handing to SDL.
10161019
// This is more a suggestion, and not really a guarantee...
10171020
let dst_size = self.capacity(src.len());
10181021

10191022
// Bounce into SDL2 heap allocation as SDL_ConvertAudio may rewrite the pointer.
1020-
raw.buf = sys::SDL_malloc(dst_size as _) as *mut _;
1021-
use std::convert::TryInto;
10221023
raw.len = src.len().try_into().expect("Buffer length overflow");
1024+
raw.buf = sys::SDL_malloc(dst_size as _) as *mut _;
10231025
if raw.buf.is_null() {
10241026
panic!("Failed SDL_malloc needed for SDL_ConvertAudio");
10251027
}
10261028
// raw.buf is dst_size long, but we want to copy into only the first src.len bytes.
10271029
assert!(src.len() <= dst_size);
1028-
std::slice::from_raw_parts_mut(raw.buf, src.len()).copy_from_slice(src.as_ref());
1030+
from_raw_parts_mut(raw.buf, src.len()).copy_from_slice(src.as_ref());
10291031

10301032
let ret = sys::SDL_ConvertAudio(&mut raw);
10311033
// There's no reason for SDL_ConvertAudio to fail.
@@ -1038,7 +1040,7 @@ impl AudioCVT {
10381040
let outlen: usize = raw.len_cvt.try_into().expect("Buffer size rollover");
10391041
debug_assert!(outlen <= dst_size);
10401042
src.resize(outlen, 0);
1041-
src.copy_from_slice(std::slice::from_raw_parts_mut(raw.buf, outlen));
1043+
src.copy_from_slice(from_raw_parts_mut(raw.buf, outlen));
10421044
sys::SDL_free(raw.buf as *mut _);
10431045

10441046
src

0 commit comments

Comments
 (0)