mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 08:26:30 +03:00
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:
@@ -79,13 +79,13 @@ impl Aheader {
|
||||
let optional_field = unsafe { (*field).fld_data.fld_optional_field };
|
||||
if !optional_field.is_null()
|
||||
&& unsafe { !(*optional_field).fld_name.is_null() }
|
||||
&& unsafe { CStr::from_ptr((*optional_field).fld_name).to_str().unwrap() }
|
||||
&& unsafe { CStr::from_ptr((*optional_field).fld_name).to_str().unwrap_or_default() }
|
||||
== "Autocrypt"
|
||||
{
|
||||
let value = unsafe {
|
||||
CStr::from_ptr((*optional_field).fld_value)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
if let Ok(test) = Self::from_str(value) {
|
||||
|
||||
Reference in New Issue
Block a user