@@ -1163,43 +1163,39 @@ unsafe fn COVER_tryParameters(opaque: *mut core::ffi::c_void) {
11631163 let parameters = ( * data) . parameters ;
11641164 let dictBufferCapacity = ( * data) . dictBufferCapacity ;
11651165 let totalCompressedSize = Error :: GENERIC . to_error_code ( ) ;
1166- let dict = malloc ( dictBufferCapacity) as * mut u8 ;
1166+ let mut dict: Box < [ u8 ] > = Box :: from ( vec ! [ 0u8 ; dictBufferCapacity] ) ;
11671167 let mut selection = COVER_dictSelectionError ( Error :: GENERIC . to_error_code ( ) ) ;
11681168 let mut freqs = ( * ctx) . freqs . clone ( ) ;
11691169 let displayLevel = ( * ctx) . displayLevel ;
11701170 let mut activeDmers =
11711171 COVER_map_t :: new ( ( parameters. k ) . wrapping_sub ( parameters. d ) . wrapping_add ( 1 ) ) ;
1172- if dict. is_null ( ) {
1173- if displayLevel >= 1 {
1174- eprintln ! ( "Failed to allocate buffers: out of memory" ) ;
1175- }
1176- } else {
1177- let tail = COVER_buildDictionary (
1178- ctx,
1179- freqs. as_mut_ptr ( ) ,
1180- & mut activeDmers,
1181- dict as * mut core:: ffi:: c_void ,
1182- dictBufferCapacity,
1183- parameters,
1184- ) ;
1185- selection = COVER_selectDict (
1186- dict. add ( tail) ,
1187- dictBufferCapacity,
1188- dictBufferCapacity. wrapping_sub ( tail) ,
1189- ( * ctx) . samples . as_ptr ( ) ,
1190- ( * ctx) . samplesSizes . as_ptr ( ) ,
1191- ( * ctx) . nbTrainSamples as core:: ffi:: c_uint ,
1192- ( * ctx) . nbTrainSamples ,
1193- ( * ctx) . nbSamples ,
1194- parameters,
1195- ( * ctx) . offsets . as_mut_ptr ( ) ,
1196- totalCompressedSize,
1197- ) ;
1198- if COVER_dictSelectionIsError ( selection) != 0 && displayLevel >= 1 {
1199- eprintln ! ( "Failed to select dictionary" ) ;
1200- }
1172+
1173+ let tail = COVER_buildDictionary (
1174+ ctx,
1175+ freqs. as_mut_ptr ( ) ,
1176+ & mut activeDmers,
1177+ dict. as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
1178+ dictBufferCapacity,
1179+ parameters,
1180+ ) ;
1181+ selection = COVER_selectDict (
1182+ dict. as_mut_ptr ( ) . add ( tail) ,
1183+ dictBufferCapacity,
1184+ dictBufferCapacity. wrapping_sub ( tail) ,
1185+ ( * ctx) . samples . as_ptr ( ) ,
1186+ ( * ctx) . samplesSizes . as_ptr ( ) ,
1187+ ( * ctx) . nbTrainSamples as core:: ffi:: c_uint ,
1188+ ( * ctx) . nbTrainSamples ,
1189+ ( * ctx) . nbSamples ,
1190+ parameters,
1191+ ( * ctx) . offsets . as_mut_ptr ( ) ,
1192+ totalCompressedSize,
1193+ ) ;
1194+
1195+ if COVER_dictSelectionIsError ( selection) != 0 && displayLevel >= 1 {
1196+ eprintln ! ( "Failed to select dictionary" ) ;
12011197 }
1202- free ( dict as * mut core :: ffi :: c_void ) ;
1198+ drop ( dict) ;
12031199 COVER_best_finish ( ( * data) . best , parameters, selection) ;
12041200 free ( data as * mut core:: ffi:: c_void ) ;
12051201 COVER_map_destroy ( & mut activeDmers) ;
0 commit comments