Kill to_cstring with fire

I swear I already did this, see #273.
This commit is contained in:
Floris Bruynooghe
2019-08-04 00:14:49 +02:00
committed by Floris Bruynooghe
parent d814dffbb0
commit 0051720d1b
3 changed files with 7 additions and 13 deletions

View File

@@ -310,12 +310,12 @@ pub unsafe fn dc_open(context: &Context, dbfile: &str, blobdir: Option<&str>) ->
if 0 != dc_is_open(context) {
return false;
}
*context.dbfile.write().unwrap() = to_cstring(dbfile);
*context.dbfile.write().unwrap() = dbfile.strdup();
if blobdir.is_some() && blobdir.unwrap().len() > 0 {
let dir = to_cstring(dc_ensure_no_slash_safe(blobdir.unwrap()));
let dir = dc_ensure_no_slash_safe(blobdir.unwrap()).strdup();
*context.blobdir.write().unwrap() = dir;
} else {
let dir = to_cstring(dbfile.to_string() + "-blobs");
let dir = (dbfile.to_string() + "-blobs").strdup();
dc_create_folder(context, dir);
*context.blobdir.write().unwrap() = dir;
}

View File

@@ -45,12 +45,12 @@ pub unsafe fn dc_get_securejoin_qr(
dc_ensure_secret_key_exists(context);
invitenumber = dc_token_lookup(context, DC_TOKEN_INVITENUMBER, group_chat_id);
if invitenumber.is_null() {
invitenumber = to_cstring(dc_create_id());
invitenumber = dc_create_id().strdup();
dc_token_save(context, DC_TOKEN_INVITENUMBER, group_chat_id, invitenumber);
}
auth = dc_token_lookup(context, DC_TOKEN_AUTH, group_chat_id);
if auth.is_null() {
auth = to_cstring(dc_create_id());
auth = dc_create_id().strdup();
dc_token_save(context, DC_TOKEN_AUTH, group_chat_id, auth);
}
let self_addr = context.sql.get_config(context, "configured_addr");

View File

@@ -775,7 +775,7 @@ pub unsafe fn dc_create_outgoing_rfc724_mid(
- the message ID should be globally unique
- do not add a counter or any private data as as this may give unneeded information to the receiver */
let mut rand1: *mut libc::c_char = 0 as *mut libc::c_char;
let rand2: *mut libc::c_char = to_cstring(dc_create_id());
let rand2: *mut libc::c_char = dc_create_id().strdup();
let ret: *mut libc::c_char;
let mut at_hostname: *const libc::c_char = strchr(from_addr, '@' as i32);
if at_hostname.is_null() {
@@ -789,7 +789,7 @@ pub unsafe fn dc_create_outgoing_rfc724_mid(
at_hostname,
)
} else {
rand1 = to_cstring(dc_create_id());
rand1 = dc_create_id().strdup();
ret = dc_mprintf(
b"Mr.%s.%s%s\x00" as *const u8 as *const libc::c_char,
rand1,
@@ -1545,12 +1545,6 @@ impl<T: AsRef<str>> StrExt for T {
}
}
/// Needs to free the result after use!
pub unsafe fn to_cstring<S: AsRef<str>>(s: S) -> *mut libc::c_char {
let cstr = CString::new(s.as_ref()).expect("invalid string converted");
dc_strdup(cstr.as_ref().as_ptr())
}
pub fn to_string(s: *const libc::c_char) -> String {
if s.is_null() {
return "".into();