mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Make dc_array_sort_ids() safe and move it into impl
This commit is contained in:
@@ -137,6 +137,14 @@ impl dc_array_t {
|
||||
panic!("Attempt to search for id in array of other type");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sort_ids(&mut self) {
|
||||
if let dc_array_t::Uint(v) = self {
|
||||
v.sort();
|
||||
} else {
|
||||
panic!("Attempt to sort array of something other than uints");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_unref(array: *mut dc_array_t) {
|
||||
@@ -340,17 +348,6 @@ pub unsafe fn dc_array_duplicate(array: *const dc_array_t) -> *mut dc_array_t {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_sort_ids(array: *mut dc_array_t) {
|
||||
if array.is_null() || (*array).len() <= 1 {
|
||||
return;
|
||||
}
|
||||
if let dc_array_t::Uint(v) = &mut *array {
|
||||
v.sort();
|
||||
} else {
|
||||
panic!("Attempt to sort array of something other than uints");
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn dc_array_get_string(
|
||||
array: *const dc_array_t,
|
||||
sep: *const libc::c_char,
|
||||
@@ -417,7 +414,7 @@ mod tests {
|
||||
dc_array_add_id(arr, 0 as uint32_t);
|
||||
dc_array_add_id(arr, 5000 as uint32_t);
|
||||
|
||||
dc_array_sort_ids(arr);
|
||||
(*arr).sort_ids();
|
||||
|
||||
assert_eq!(dc_array_get_id(arr, 0 as size_t), 0);
|
||||
assert_eq!(dc_array_get_id(arr, 1 as size_t), 7);
|
||||
|
||||
@@ -1554,7 +1554,7 @@ unsafe fn search_chat_ids_by_contact_ids(
|
||||
i += 1
|
||||
}
|
||||
if !(dc_array_get_cnt(contact_ids) == 0) {
|
||||
dc_array_sort_ids(contact_ids);
|
||||
(*contact_ids).sort_ids();
|
||||
contact_ids_str =
|
||||
dc_array_get_string(contact_ids, b",\x00" as *const u8 as *const libc::c_char);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user