Merge pull request #261 from link2xt/dc_timestamp_to_str

Remove unsafe version of dc_timestamp_to_str
This commit is contained in:
Friedel Ziegelmayer
2019-07-30 00:19:33 +02:00
committed by GitHub
3 changed files with 9 additions and 19 deletions

View File

@@ -229,7 +229,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t
DC_STATE_OUT_FAILED => " !!",
_ => "",
};
let temp2: *mut libc::c_char = dc_timestamp_to_str(dc_msg_get_timestamp(msg));
let temp2 = dc_timestamp_to_str(dc_msg_get_timestamp(msg));
let msgtext: *mut libc::c_char = dc_msg_get_text(msg);
info!(
context,
@@ -266,10 +266,9 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t
""
},
statestr,
as_str(temp2),
&temp2,
);
free(msgtext as *mut libc::c_void);
free(temp2 as *mut libc::c_void);
free(contact_name as *mut libc::c_void);
dc_contact_unref(contact);
}
@@ -682,7 +681,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
if !text1.is_null() { ": " } else { "" },
to_string(text2),
statestr,
as_str(timestr),
&timestr,
if 0 != dc_chat_is_sending_locations(chat) {
"📍"
} else {
@@ -691,7 +690,6 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
);
free(text1 as *mut libc::c_void);
free(text2 as *mut libc::c_void);
free(timestr as *mut libc::c_void);
dc_lot_unref(lot);
dc_chat_unref(chat);
info!(
@@ -886,7 +884,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
0,
"Loc#{}: {}: lat={} lng={} acc={} Chat#{} Contact#{} Msg#{} {}",
dc_array_get_id(loc, j as size_t),
as_str(timestr_0),
&timestr_0,
dc_array_get_latitude(loc, j as size_t),
dc_array_get_longitude(loc, j as size_t),
dc_array_get_accuracy(loc, j as size_t),
@@ -899,7 +897,6 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
"-"
},
);
free(timestr_0 as *mut libc::c_void);
free(marker as *mut libc::c_void);
j += 1
}

View File

@@ -70,7 +70,7 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
let rawtxt = rawtxt.unwrap();
let rawtxt = dc_truncate_str(rawtxt.trim(), 100000);
let fts = dc_timestamp_to_str_safe(dc_msg_get_timestamp(msg));
let fts = dc_timestamp_to_str(dc_msg_get_timestamp(msg));
ret += &format!("Sent: {}", fts);
p = dc_contact_get_name_n_addr(contact_from);
@@ -79,13 +79,12 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
ret += "\n";
if (*msg).from_id != 1 as libc::c_uint {
p = dc_timestamp_to_str(if 0 != (*msg).timestamp_rcvd {
let s = dc_timestamp_to_str(if 0 != (*msg).timestamp_rcvd {
(*msg).timestamp_rcvd
} else {
(*msg).timestamp_sort
});
ret += &format!("Received: {}", as_str(p));
free(p as *mut libc::c_void);
ret += &format!("Received: {}", &s);
ret += "\n";
}
@@ -109,7 +108,7 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
|rows| {
for row in rows {
let (contact_id, ts) = row?;
let fts = dc_timestamp_to_str_safe(ts);
let fts = dc_timestamp_to_str(ts);
ret += &format!("Read: {}", fts);
let contact = dc_contact_new(context);

View File

@@ -669,13 +669,7 @@ pub unsafe fn dc_timestamp_from_date(date_time: *mut mailimf_date_time) -> i64 {
* date/time tools
******************************************************************************/
/* the return value must be free()'d */
pub unsafe fn dc_timestamp_to_str(wanted: i64) -> *mut libc::c_char {
let res = dc_timestamp_to_str_safe(wanted);
to_cstring(res)
}
pub fn dc_timestamp_to_str_safe(wanted: i64) -> String {
pub fn dc_timestamp_to_str(wanted: i64) -> String {
let ts = chrono::Utc.timestamp(wanted, 0);
ts.format("%Y.%m.%d %H:%M:%S").to_string()
}