11use std:: cmp:: Ordering ;
2+ use std:: mem:: MaybeUninit ;
23use std:: ops:: Range ;
34use std:: sync:: { Condvar , Mutex } ;
45
@@ -887,7 +888,6 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
887888 let mut totalCompressedSize = Error :: GENERIC . to_error_code ( ) ;
888889 let mut cctx = core:: ptr:: null_mut :: < ZSTD_CCtx > ( ) ;
889890 let mut cdict = core:: ptr:: null_mut :: < ZSTD_CDict > ( ) ;
890- let mut dst = core:: ptr:: null_mut :: < core:: ffi:: c_void > ( ) ;
891891 let mut dstCapacity: size_t = 0 ;
892892 let mut i: size_t = 0 ;
893893 let mut maxSampleSize = 0 ;
@@ -905,14 +905,14 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
905905 i = i. wrapping_add ( 1 ) ;
906906 }
907907 dstCapacity = ZSTD_compressBound ( maxSampleSize) ;
908- dst = malloc ( dstCapacity) ;
908+ let mut dst: Box < [ MaybeUninit < u8 > ] > = Box :: new_uninit_slice ( dstCapacity) ;
909909 cctx = ZSTD_createCCtx ( ) ;
910910 cdict = ZSTD_createCDict (
911911 dict as * const core:: ffi:: c_void ,
912912 dictBufferCapacity,
913913 parameters. zParams . compressionLevel ,
914914 ) ;
915- if !( dst . is_null ( ) || cctx. is_null ( ) || cdict. is_null ( ) ) {
915+ if !( cctx. is_null ( ) || cdict. is_null ( ) ) {
916916 totalCompressedSize = dictBufferCapacity;
917917 i = if parameters. splitPoint < 1.0f64 {
918918 nbTrainSamples
@@ -922,7 +922,7 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
922922 while i < nbSamples {
923923 let size = ZSTD_compress_usingCDict (
924924 cctx,
925- dst,
925+ dst. as_mut_ptr ( ) . cast :: < core :: ffi :: c_void > ( ) ,
926926 dstCapacity,
927927 samples. add ( * offsets. add ( i) ) as * const core:: ffi:: c_void ,
928928 * samplesSizes. add ( i) ,
@@ -939,9 +939,7 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
939939 }
940940 ZSTD_freeCCtx ( cctx) ;
941941 ZSTD_freeCDict ( cdict) ;
942- if !dst. is_null ( ) {
943- free ( dst) ;
944- }
942+ drop ( dst) ;
945943 totalCompressedSize
946944}
947945
0 commit comments