if in doubt, prefer unwrap_or_default()

if the past we had lots of crashes because of unexpected unwrap failures,
mostly related to string.
this commit avoids them eg. for string-conversions that may panic
eg. when encountering a null-byte or by logical programming errors
where an object is assumed to be set but is not under unexpected circumstances.
This commit is contained in:
B. Petersen
2019-10-04 00:05:14 +02:00
parent 93f0f5ccae
commit 477af413c6
28 changed files with 83 additions and 83 deletions

View File

@@ -263,7 +263,7 @@ pub fn continue_key_transfer(context: &Context, msg_id: u32, setup_code: &str) -
if msg.is_err() {
bail!("Message is no Autocrypt Setup Message.");
}
let msg = msg.unwrap();
let msg = msg.unwrap_or_default();
ensure!(
msg.is_setupmessage(),
"Message is no Autocrypt Setup Message."
@@ -346,7 +346,7 @@ fn set_self_key(
context,
&public_key,
&private_key,
self_addr.unwrap(),
self_addr.unwrap_or_default(),
set_default,
&context.sql,
) {
@@ -682,7 +682,7 @@ fn export_backup(context: &Context, dir: impl AsRef<Path>) -> Result<()> {
}
Ok(())
}
).unwrap();
).unwrap_or_default();
} else {
error!(
context,
@@ -763,7 +763,7 @@ fn import_self_keys(context: &Context, dir: impl AsRef<Path>) -> Result<()> {
}
let ccontent = if let Ok(content) = dc_read_file(context, &path_plus_name) {
key = String::from_utf8_lossy(&content).to_string();
CString::new(content).unwrap()
CString::new(content).unwrap_or_default()
} else {
continue;
};