@@ -261,30 +261,26 @@ pub extern "C" fn request_read_error_message(
261261
262262 if let Some ( progress_info) = tracker. get ( & request_id) {
263263 let progress = progress_info. read ( ) . unwrap ( ) ;
264- if let Some ( ref response) = progress. final_response {
265- if let Err ( ref error_msg) = response. body {
266- let msg_len = error_msg. len ( ) ;
267- unsafe { * num_bytes = msg_len as u32 } ;
268-
269- // Allocate memory for the string + null terminator
270- let c_str_ptr = unsafe { libc:: malloc ( msg_len + 1 ) as * mut c_char } ;
271- if c_str_ptr. is_null ( ) {
272- unsafe { * num_bytes = 0 } ;
273- return ptr:: null_mut ( ) ;
274- }
264+ if let Some ( ref response) = progress. final_response
265+ && let Err ( ref error_msg) = response. body
266+ {
267+ let msg_len = error_msg. len ( ) ;
268+ unsafe { * num_bytes = msg_len as u32 } ;
275269
276- // Copy the string and add null terminator
277- unsafe {
278- std:: ptr:: copy_nonoverlapping (
279- error_msg. as_ptr ( ) ,
280- c_str_ptr as * mut u8 ,
281- msg_len,
282- ) ;
283- * ( c_str_ptr. add ( msg_len) ) = 0 ;
284- }
270+ // Allocate memory for the string + null terminator
271+ let c_str_ptr = unsafe { libc:: malloc ( msg_len + 1 ) as * mut c_char } ;
272+ if c_str_ptr. is_null ( ) {
273+ unsafe { * num_bytes = 0 } ;
274+ return ptr:: null_mut ( ) ;
275+ }
285276
286- return c_str_ptr;
277+ // Copy the string and add null terminator
278+ unsafe {
279+ std:: ptr:: copy_nonoverlapping ( error_msg. as_ptr ( ) , c_str_ptr as * mut u8 , msg_len) ;
280+ * ( c_str_ptr. add ( msg_len) ) = 0 ;
287281 }
282+
283+ return c_str_ptr;
288284 }
289285 }
290286
@@ -306,26 +302,26 @@ pub extern "C" fn request_read_error_url(
306302
307303 if let Some ( progress_info) = tracker. get ( & request_id) {
308304 let progress = progress_info. read ( ) . unwrap ( ) ;
309- if let Some ( ref response) = progress. final_response {
310- if let Some ( ref url) = response. error_url {
311- let url_len = url. len ( ) ;
312- unsafe { * num_bytes = url_len as u32 } ;
313-
314- // Allocate memory for the string + null terminator
315- let c_str_ptr = unsafe { libc:: malloc ( url_len + 1 ) as * mut c_char } ;
316- if c_str_ptr. is_null ( ) {
317- unsafe { * num_bytes = 0 } ;
318- return ptr:: null_mut ( ) ;
319- }
305+ if let Some ( ref response) = progress. final_response
306+ && let Some ( ref url) = response. error_url
307+ {
308+ let url_len = url. len ( ) ;
309+ unsafe { * num_bytes = url_len as u32 } ;
320310
321- // Copy the string and add null terminator
322- unsafe {
323- std:: ptr:: copy_nonoverlapping ( url. as_ptr ( ) , c_str_ptr as * mut u8 , url_len) ;
324- * ( c_str_ptr. add ( url_len) ) = 0 ;
325- }
311+ // Allocate memory for the string + null terminator
312+ let c_str_ptr = unsafe { libc:: malloc ( url_len + 1 ) as * mut c_char } ;
313+ if c_str_ptr. is_null ( ) {
314+ unsafe { * num_bytes = 0 } ;
315+ return ptr:: null_mut ( ) ;
316+ }
326317
327- return c_str_ptr;
318+ // Copy the string and add null terminator
319+ unsafe {
320+ std:: ptr:: copy_nonoverlapping ( url. as_ptr ( ) , c_str_ptr as * mut u8 , url_len) ;
321+ * ( c_str_ptr. add ( url_len) ) = 0 ;
328322 }
323+
324+ return c_str_ptr;
329325 }
330326 }
331327
@@ -347,26 +343,26 @@ pub extern "C" fn request_read_error_source(
347343
348344 if let Some ( progress_info) = tracker. get ( & request_id) {
349345 let progress = progress_info. read ( ) . unwrap ( ) ;
350- if let Some ( ref response) = progress. final_response {
351- if let Some ( ref source) = response. error_source {
352- let src_len = source. len ( ) ;
353- unsafe { * num_bytes = src_len as u32 } ;
354-
355- // Allocate memory for the string + null terminator
356- let c_str_ptr = unsafe { libc:: malloc ( src_len + 1 ) as * mut c_char } ;
357- if c_str_ptr. is_null ( ) {
358- unsafe { * num_bytes = 0 } ;
359- return ptr:: null_mut ( ) ;
360- }
346+ if let Some ( ref response) = progress. final_response
347+ && let Some ( ref source) = response. error_source
348+ {
349+ let src_len = source. len ( ) ;
350+ unsafe { * num_bytes = src_len as u32 } ;
361351
362- // Copy the string and add null terminator
363- unsafe {
364- std:: ptr:: copy_nonoverlapping ( source. as_ptr ( ) , c_str_ptr as * mut u8 , src_len) ;
365- * ( c_str_ptr. add ( src_len) ) = 0 ;
366- }
352+ // Allocate memory for the string + null terminator
353+ let c_str_ptr = unsafe { libc:: malloc ( src_len + 1 ) as * mut c_char } ;
354+ if c_str_ptr. is_null ( ) {
355+ unsafe { * num_bytes = 0 } ;
356+ return ptr:: null_mut ( ) ;
357+ }
367358
368- return c_str_ptr;
359+ // Copy the string and add null terminator
360+ unsafe {
361+ std:: ptr:: copy_nonoverlapping ( source. as_ptr ( ) , c_str_ptr as * mut u8 , src_len) ;
362+ * ( c_str_ptr. add ( src_len) ) = 0 ;
369363 }
364+
365+ return c_str_ptr;
370366 }
371367 }
372368
0 commit comments