Skip to content

Commit 7138e1f

Browse files
committed
fixed linter errors
1 parent d09e029 commit 7138e1f

File tree

2 files changed

+65
-71
lines changed

2 files changed

+65
-71
lines changed

src/ffi/multipart.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,23 @@ pub extern "C" fn multipart_form_add_bytes(
196196
let mut part = multipart::Part::bytes(data_vec);
197197

198198
// Add filename if provided
199-
if !filename.is_null() {
200-
if let Ok(filename_str) = unsafe { CStr::from_ptr(filename).to_str() } {
201-
if !filename_str.is_empty() {
202-
part = part.file_name(filename_str.to_string());
203-
}
204-
}
199+
if !filename.is_null()
200+
&& let Ok(filename_str) = unsafe { CStr::from_ptr(filename).to_str() }
201+
&& !filename_str.is_empty()
202+
{
203+
part = part.file_name(filename_str.to_string());
205204
}
206205

207206
// Add MIME type if provided
208-
if !mime_type.is_null() {
209-
if let Ok(mime_str) = unsafe { CStr::from_ptr(mime_type).to_str() } {
210-
if !mime_str.is_empty() {
211-
match part.mime_str(mime_str) {
212-
Ok(p) => part = p,
213-
Err(e) => {
214-
wrapper.error_message = Some(format!("Invalid MIME type: {e}"));
215-
return false;
216-
}
217-
}
207+
if !mime_type.is_null()
208+
&& let Ok(mime_str) = unsafe { CStr::from_ptr(mime_type).to_str() }
209+
&& !mime_str.is_empty()
210+
{
211+
match part.mime_str(mime_str) {
212+
Ok(p) => part = p,
213+
Err(e) => {
214+
wrapper.error_message = Some(format!("Invalid MIME type: {e}"));
215+
return false;
218216
}
219217
}
220218
}

src/ffi/request.rs

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)