diff --git a/src/context.rs b/src/context.rs index ba12edc21..1480c8181 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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; } diff --git a/src/dc_securejoin.rs b/src/dc_securejoin.rs index 3e908a5c1..90573412f 100644 --- a/src/dc_securejoin.rs +++ b/src/dc_securejoin.rs @@ -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"); diff --git a/src/dc_tools.rs b/src/dc_tools.rs index ee23c1b9f..39bfddb01 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -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> StrExt for T { } } -/// Needs to free the result after use! -pub unsafe fn to_cstring>(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();