From 9cae075b6f6a7e65b116d94f85f1c52e612e8b2f Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 4 Oct 2019 22:53:23 +0200 Subject: [PATCH] target detailed checks of @flub --- src/chat.rs | 35 ++++++++++++++++------------------- src/chatlist.rs | 7 +------ src/config.rs | 9 ++------- src/configure/auto_mozilla.rs | 2 +- src/contact.rs | 2 +- src/dc_receive_imf.rs | 2 +- src/dc_tools.rs | 14 +++++++------- 7 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index fe90cd384..c2ca192ea 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -287,7 +287,7 @@ impl Chat { if self.typ == Chattype::Group || self.typ == Chattype::VerifiedGroup { if self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 { self.param.remove(Param::Unpromoted); - self.update_param(context).unwrap_or_default(); + self.update_param(context)?; } } } @@ -663,7 +663,7 @@ fn prepare_msg_common(context: &Context, chat_id: u32, msg: &mut Message) -> Res msg.type_0 ); - let mut path_filename = path_filename.unwrap_or_default().to_string(); + let mut path_filename = path_filename.unwrap().to_string(); if msg.state == MessageState::OutPreparing && !dc_is_blobdir_path(context, &path_filename) { bail!("Files must be created in the blob-directory."); @@ -1367,7 +1367,7 @@ pub(crate) fn add_contact_to_chat_ex( } if from_handshake && chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 { chat.param.remove(Param::Unpromoted); - chat.update_param(context).unwrap_or_default(); + chat.update_param(context)?; } let self_addr = context .get_config(Config::ConfiguredAddr) @@ -1502,7 +1502,7 @@ pub fn remove_contact_from_chat( if chat.is_promoted() { msg.type_0 = Viewtype::Text; if contact.id == DC_CONTACT_ID_SELF { - set_group_explicitly_left(context, chat.grpid).unwrap_or_default(); + set_group_explicitly_left(context, chat.grpid)?; msg.text = Some(context.stock_system_msg( StockMessage::MsgGroupLeft, "", @@ -1711,7 +1711,7 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result< let mut created_db_entries = Vec::new(); let mut curr_timestamp: i64; - unarchive(context, chat_id).unwrap_or_default(); + unarchive(context, chat_id)?; if let Ok(mut chat) = Chat::load_from_db(context, chat_id) { curr_timestamp = dc_create_smeared_timestamps(context, msg_ids.len()); let idsstr = msg_ids @@ -1721,18 +1721,15 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result< (if i == 0 { acc } else { acc + "," }) + &n.to_string() }); - let ids = context - .sql - .query_map( - format!( - "SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id", - idsstr - ), - params![], - |row| row.get::<_, i32>(0), - |ids| ids.collect::, _>>().map_err(Into::into), - ) - .unwrap_or_default(); // TODO: better error handling + let ids = context.sql.query_map( + format!( + "SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id", + idsstr + ), + params![], + |row| row.get::<_, i32>(0), + |ids| ids.collect::, _>>().map_err(Into::into), + )?; for id in ids { let src_msg_id = id; @@ -1740,7 +1737,7 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result< if msg.is_err() { break; } - let mut msg = msg.unwrap_or_default(); + let mut msg = msg.unwrap(); let original_param = msg.param.clone(); if msg.from_id != DC_CONTACT_ID_SELF { msg.param.set_int(Param::Forwarded, 1); @@ -1870,7 +1867,7 @@ mod tests { fn test_get_draft_no_draft() { let t = dummy_context(); let chat_id = create_by_contact_id(&t.ctx, DC_CONTACT_ID_SELF).unwrap(); - let draft = get_draft(&t.ctx, chat_id).unwrap_or_default(); + let draft = get_draft(&t.ctx, chat_id).unwrap(); assert!(draft.is_none()); } diff --git a/src/chatlist.rs b/src/chatlist.rs index 7900f6ea7..608ff1bf9 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -290,12 +290,7 @@ impl Chatlist { { ret.text2 = Some(context.stock_str(StockMessage::NoMessages).to_string()); } else { - ret.fill( - &mut lastmsg.unwrap_or_default(), - chat, - lastcontact.as_ref(), - context, - ); + ret.fill(&mut lastmsg.unwrap(), chat, lastcontact.as_ref(), context); } ret diff --git a/src/config.rs b/src/config.rs index 5fdd3eb1e..24fd80d0c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -79,12 +79,7 @@ impl Context { let value = match key { Config::Selfavatar => { let rel_path = self.sql.get_raw_config(self, key); - rel_path.map(|p| { - dc_get_abs_path(self, &p) - .to_str() - .unwrap_or_default() - .to_string() - }) + rel_path.map(|p| dc_get_abs_path(self, &p).to_string_lossy().into_owned()) } Config::SysVersion => Some((&*DC_VERSION_STR).clone()), Config::SysMsgsizeMaxRecommended => Some(format!("{}", 24 * 1024 * 1024 / 4 * 3)), @@ -118,7 +113,7 @@ impl Context { pub fn set_config(&self, key: Config, value: Option<&str>) -> Result<(), Error> { match key { Config::Selfavatar if value.is_some() => { - let rel_path = std::fs::canonicalize(value.unwrap_or_default())?; + let rel_path = std::fs::canonicalize(value.unwrap())?; self.sql .set_raw_config(self, key, Some(&rel_path.to_string_lossy())) } diff --git a/src/configure/auto_mozilla.rs b/src/configure/auto_mozilla.rs index bf49cba07..005cc5fcb 100644 --- a/src/configure/auto_mozilla.rs +++ b/src/configure/auto_mozilla.rs @@ -40,7 +40,7 @@ pub unsafe fn moz_autoconfigure( free(xml_raw as *mut libc::c_void); return None; } - let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap_or_default()); + let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap()); let in_emaildomain = &in_emaildomain[1..]; let mut reader = quick_xml::Reader::from_str(as_str(xml_raw)); diff --git a/src/contact.rs b/src/contact.rs index 183795543..c9842bce7 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1030,7 +1030,7 @@ fn split_address_book(book: &str) -> Vec<(&str, &str)> { .chunks(2) .into_iter() .filter_map(|mut chunk| { - let name = chunk.next().unwrap_or_default(); + let name = chunk.next().unwrap(); let addr = match chunk.next() { Some(a) => a, None => return None, diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index dcea2049f..7c8f25050 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -581,7 +581,7 @@ unsafe fn add_parts( ); // unarchive chat - chat::unarchive(context, *chat_id).unwrap_or_default(); + chat::unarchive(context, *chat_id)?; // if the mime-headers should be saved, find out its size // (the mime-header ends with an empty line) diff --git a/src/dc_tools.rs b/src/dc_tools.rs index ff1103de6..25e0228fa 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -330,13 +330,13 @@ fn encode_66bits_as_base64(v1: u32, v2: u32, fill: u32) -> String { let mut wrapped_writer = Vec::new(); { let mut enc = base64::write::EncoderWriter::new(&mut wrapped_writer, base64::URL_SAFE); - enc.write_u32::(v1).unwrap_or_default(); - enc.write_u32::(v2).unwrap_or_default(); - enc.write_u8(((fill & 0x3) as u8) << 6).unwrap_or_default(); - enc.finish().unwrap_or_default(); + enc.write_u32::(v1).unwrap(); + enc.write_u32::(v2).unwrap(); + enc.write_u8(((fill & 0x3) as u8) << 6).unwrap(); + enc.finish().unwrap(); } assert_eq!(wrapped_writer.pop(), Some(b'A')); // Remove last "A" - String::from_utf8(wrapped_writer).unwrap_or_default() + String::from_utf8(wrapped_writer).unwrap() } pub(crate) fn dc_create_incoming_rfc724_mid( @@ -386,7 +386,7 @@ pub(crate) fn dc_extract_grpid_from_rfc724_mid(mid: &str) -> Option<&str> { if let Some(grpid_len) = mid_without_offset.find('.') { /* strict length comparison, the 'Gr.' magic is weak enough */ if grpid_len == 11 || grpid_len == 16 { - return Some(mid_without_offset.get(0..grpid_len).unwrap_or_default()); + return Some(mid_without_offset.get(0..grpid_len).unwrap()); } } } @@ -892,7 +892,7 @@ fn as_path_unicode<'a>(s: *const libc::c_char) -> &'a std::path::Path { pub(crate) fn time() -> i64 { SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) - .unwrap_or_default() + .unwrap() .as_secs() as i64 }