@@ -1010,22 +1010,24 @@ impl AudioCVT {
1010
1010
//! Certain conversions may cause buffer overflows. See AngryLawyer/rust-sdl2 issue #270.
1011
1011
unsafe {
1012
1012
if self . raw . needed != 0 {
1013
+ use std:: convert:: TryInto ;
1014
+ use std:: slice:: from_raw_parts_mut;
1015
+
1013
1016
let mut raw = self . raw ;
1014
1017
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.
1016
1019
// This is more a suggestion, and not really a guarantee...
1017
1020
let dst_size = self . capacity ( src. len ( ) ) ;
1018
1021
1019
1022
// 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 ;
1022
1023
raw. len = src. len ( ) . try_into ( ) . expect ( "Buffer length overflow" ) ;
1024
+ raw. buf = sys:: SDL_malloc ( dst_size as _ ) as * mut _ ;
1023
1025
if raw. buf . is_null ( ) {
1024
1026
panic ! ( "Failed SDL_malloc needed for SDL_ConvertAudio" ) ;
1025
1027
}
1026
1028
// raw.buf is dst_size long, but we want to copy into only the first src.len bytes.
1027
1029
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 ( ) ) ;
1029
1031
1030
1032
let ret = sys:: SDL_ConvertAudio ( & mut raw) ;
1031
1033
// There's no reason for SDL_ConvertAudio to fail.
@@ -1038,7 +1040,7 @@ impl AudioCVT {
1038
1040
let outlen: usize = raw. len_cvt . try_into ( ) . expect ( "Buffer size rollover" ) ;
1039
1041
debug_assert ! ( outlen <= dst_size) ;
1040
1042
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) ) ;
1042
1044
sys:: SDL_free ( raw. buf as * mut _ ) ;
1043
1045
1044
1046
src
0 commit comments