From c71589a710d9dcc034153c79fe90a313649d0ff0 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 28 Aug 2019 13:37:26 +0200 Subject: [PATCH 1/3] handle ffi-failures compatible to core-c --- deltachat-ffi/src/lib.rs | 843 +++++++++++++++++++++++++++++---------- 1 file changed, 642 insertions(+), 201 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index a5eb672bc..a03d6a2f7 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -17,9 +17,17 @@ use std::ptr; use std::str::FromStr; use deltachat::contact::Contact; -use deltachat::dc_tools::{as_str, StrExt}; +use deltachat::dc_tools::{as_str, dc_strdup, StrExt}; use deltachat::*; +// as C lacks a good and portable error handling, +// in general, the C Interface is forgiving wrt to bad parameters. +// - objects returned by some functions +// should be passable to the functions handling that object. +// - if in doubt, the empty string is returned on failures; +// this avoids panics if the ui just forgets to handle a case +// - finally, this behaviour matches the old core-c API and UIs already depend on it + // TODO: constants // dc_context_t @@ -51,7 +59,10 @@ pub unsafe extern "C" fn dc_context_new( /// This function releases the memory of the `dc_context_t` structure. #[no_mangle] pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &mut *context; context::dc_close(context); Box::from_raw(context); @@ -59,7 +70,10 @@ pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_get_userdata(context: *mut dc_context_t) -> *mut libc::c_void { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &mut *context; context::dc_get_userdata(context) @@ -71,8 +85,10 @@ pub unsafe extern "C" fn dc_open( dbfile: *mut libc::c_char, blobdir: *mut libc::c_char, ) -> libc::c_int { - assert!(!context.is_null()); - assert!(!dbfile.is_null()); + if context.is_null() || dbfile.is_null() { + return 0; + } + let context = &mut *context; let dbfile_str = dc_tools::as_str(dbfile); @@ -86,21 +102,30 @@ pub unsafe extern "C" fn dc_open( #[no_mangle] pub unsafe extern "C" fn dc_close(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &mut *context; context::dc_close(context) } #[no_mangle] pub unsafe extern "C" fn dc_is_open(context: *mut dc_context_t) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &mut *context; context::dc_is_open(context) } #[no_mangle] pub unsafe extern "C" fn dc_get_blobdir(context: *mut dc_context_t) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return dc_strdup(ptr::null()); + } + let context = &*context; context::dc_get_blobdir(context) @@ -112,8 +137,10 @@ pub unsafe extern "C" fn dc_set_config( key: *mut libc::c_char, value: *mut libc::c_char, ) -> libc::c_int { - assert!(!context.is_null()); - assert!(!key.is_null(), "invalid key"); + if context.is_null() || key.is_null() { + return 0; + } + let context = &*context; match config::Config::from_str(dc_tools::as_str(key)) { @@ -127,10 +154,12 @@ pub unsafe extern "C" fn dc_get_config( context: *mut dc_context_t, key: *mut libc::c_char, ) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() || key.is_null() { + return dc_strdup(ptr::null()); + } + let context = &*context; - assert!(!key.is_null(), "invalid key pointer"); let key = config::Config::from_str(dc_tools::as_str(key)).expect("invalid key"); // TODO: Translating None to NULL would be more sensible than translating None @@ -140,7 +169,10 @@ pub unsafe extern "C" fn dc_get_config( #[no_mangle] pub unsafe extern "C" fn dc_get_info(context: *mut dc_context_t) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return dc_strdup(ptr::null()); + } + let context = &*context; context::dc_get_info(context) @@ -152,7 +184,9 @@ pub unsafe extern "C" fn dc_get_oauth2_url( addr: *mut libc::c_char, redirect: *mut libc::c_char, ) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); // NULL explicitly defined as "unknown" + } let context = &*context; let addr = dc_tools::to_string(addr); @@ -170,7 +204,10 @@ pub unsafe extern "C" fn dc_get_version_str() -> *mut libc::c_char { #[no_mangle] pub unsafe extern "C" fn dc_configure(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; configure::configure(context) @@ -178,7 +215,10 @@ pub unsafe extern "C" fn dc_configure(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; configure::dc_is_configured(context) @@ -186,7 +226,10 @@ pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c #[no_mangle] pub unsafe extern "C" fn dc_perform_imap_jobs(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_imap_jobs(context) @@ -194,7 +237,10 @@ pub unsafe extern "C" fn dc_perform_imap_jobs(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_imap_fetch(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_imap_fetch(context) @@ -202,7 +248,10 @@ pub unsafe extern "C" fn dc_perform_imap_fetch(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_imap_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_imap_idle(context) @@ -210,7 +259,10 @@ pub unsafe extern "C" fn dc_perform_imap_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_imap_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::interrupt_imap_idle(context) @@ -218,7 +270,10 @@ pub unsafe extern "C" fn dc_interrupt_imap_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_mvbox_fetch(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_mvbox_fetch(context) @@ -226,7 +281,10 @@ pub unsafe extern "C" fn dc_perform_mvbox_fetch(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_mvbox_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_mvbox_idle(context) @@ -234,7 +292,10 @@ pub unsafe extern "C" fn dc_perform_mvbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_mvbox_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::interrupt_mvbox_idle(context) @@ -242,7 +303,10 @@ pub unsafe extern "C" fn dc_interrupt_mvbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_sentbox_fetch(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_sentbox_fetch(context) @@ -250,7 +314,10 @@ pub unsafe extern "C" fn dc_perform_sentbox_fetch(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_sentbox_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_sentbox_idle(context) @@ -258,7 +325,10 @@ pub unsafe extern "C" fn dc_perform_sentbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_sentbox_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::interrupt_sentbox_idle(context) @@ -266,7 +336,10 @@ pub unsafe extern "C" fn dc_interrupt_sentbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_smtp_jobs(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_smtp_jobs(context) @@ -274,7 +347,10 @@ pub unsafe extern "C" fn dc_perform_smtp_jobs(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_smtp_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::perform_smtp_idle(context) @@ -282,7 +358,10 @@ pub unsafe extern "C" fn dc_perform_smtp_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_smtp_idle(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::interrupt_smtp_idle(context) @@ -290,7 +369,10 @@ pub unsafe extern "C" fn dc_interrupt_smtp_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_maybe_network(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; job::maybe_network(context) @@ -303,7 +385,10 @@ pub unsafe extern "C" fn dc_get_chatlist<'a>( query_str: *mut libc::c_char, query_id: u32, ) -> *mut dc_chatlist_t<'a> { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let qs = if query_str.is_null() { @@ -320,7 +405,10 @@ pub unsafe extern "C" fn dc_get_chatlist<'a>( #[no_mangle] pub unsafe extern "C" fn dc_create_chat_by_msg_id(context: *mut dc_context_t, msg_id: u32) -> u32 { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::create_by_msg_id(context, msg_id).unwrap_or_log_default(context, "Failed to create chat") @@ -331,7 +419,10 @@ pub unsafe extern "C" fn dc_create_chat_by_contact_id( context: *mut dc_context_t, contact_id: u32, ) -> u32 { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::create_by_contact_id(context, contact_id) @@ -343,7 +434,10 @@ pub unsafe extern "C" fn dc_get_chat_id_by_contact_id( context: *mut dc_context_t, contact_id: u32, ) -> u32 { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::get_by_contact_id(context, contact_id) @@ -356,8 +450,10 @@ pub unsafe extern "C" fn dc_prepare_msg( chat_id: u32, msg: *mut dc_msg_t, ) -> u32 { - assert!(!context.is_null()); - assert!(!msg.is_null()); + if context.is_null() || chat_id == 0 || msg.is_null() { + return 0; + } + let context = &mut *context; let msg = &mut *msg; @@ -371,8 +467,10 @@ pub unsafe extern "C" fn dc_send_msg( chat_id: u32, msg: *mut dc_msg_t, ) -> u32 { - assert!(!context.is_null()); - assert!(!msg.is_null()); + if context.is_null() || chat_id == 0 || msg.is_null() { + return 0; + } + let context = &mut *context; let msg = &mut *msg; @@ -385,8 +483,10 @@ pub unsafe extern "C" fn dc_send_text_msg( chat_id: u32, text_to_send: *mut libc::c_char, ) -> u32 { - assert!(!context.is_null()); - assert!(!text_to_send.is_null()); + if context.is_null() || text_to_send.is_null() { + return 0; + } + let context = &*context; let text_to_send = dc_tools::to_string_lossy(text_to_send); @@ -400,7 +500,10 @@ pub unsafe extern "C" fn dc_set_draft( chat_id: u32, msg: *mut dc_msg_t, ) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; let msg = if msg.is_null() { None } else { Some(&mut *msg) }; @@ -412,7 +515,10 @@ pub unsafe extern "C" fn dc_get_draft<'a>( context: *mut dc_context_t, chat_id: u32, ) -> *mut dc_msg_t<'a> { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); // NULL explicitly defined as "no draft" + } + let context = &*context; chat::get_draft(context, chat_id).into_raw() @@ -425,7 +531,10 @@ pub unsafe extern "C" fn dc_get_chat_msgs( flags: u32, marker1before: u32, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let arr = dc_array_t::from(chat::get_chat_msgs(context, chat_id, flags, marker1before)); @@ -434,7 +543,10 @@ pub unsafe extern "C" fn dc_get_chat_msgs( #[no_mangle] pub unsafe extern "C" fn dc_get_msg_cnt(context: *mut dc_context_t, chat_id: u32) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::get_msg_cnt(context, chat_id) as libc::c_int @@ -445,7 +557,10 @@ pub unsafe extern "C" fn dc_get_fresh_msg_cnt( context: *mut dc_context_t, chat_id: u32, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::get_fresh_msg_cnt(context, chat_id) as libc::c_int @@ -455,7 +570,10 @@ pub unsafe extern "C" fn dc_get_fresh_msg_cnt( pub unsafe extern "C" fn dc_get_fresh_msgs( context: *mut dc_context_t, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let arr = dc_array_t::from(context::dc_get_fresh_msgs(context)); @@ -464,7 +582,10 @@ pub unsafe extern "C" fn dc_get_fresh_msgs( #[no_mangle] pub unsafe extern "C" fn dc_marknoticed_chat(context: *mut dc_context_t, chat_id: u32) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; chat::marknoticed_chat(context, chat_id).log_err(context, "Failed marknoticed chat"); @@ -472,7 +593,10 @@ pub unsafe extern "C" fn dc_marknoticed_chat(context: *mut dc_context_t, chat_id #[no_mangle] pub unsafe extern "C" fn dc_marknoticed_all_chats(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; chat::marknoticed_all_chats(context).log_err(context, "Failed marknoticed all chats"); @@ -494,7 +618,10 @@ pub unsafe extern "C" fn dc_get_chat_media( or_msg_type2: libc::c_int, or_msg_type3: libc::c_int, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {}", msg_type)); @@ -522,7 +649,10 @@ pub unsafe extern "C" fn dc_get_next_media( or_msg_type2: libc::c_int, or_msg_type3: libc::c_int, ) -> u32 { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {}", msg_type)); @@ -540,7 +670,10 @@ pub unsafe extern "C" fn dc_archive_chat( chat_id: u32, archive: libc::c_int, ) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; let archive = if archive == 0 { @@ -556,7 +689,10 @@ pub unsafe extern "C" fn dc_archive_chat( #[no_mangle] pub unsafe extern "C" fn dc_delete_chat(context: *mut dc_context_t, chat_id: u32) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; chat::delete(context, chat_id).log_err(context, "Failed chat delete"); @@ -567,7 +703,10 @@ pub unsafe extern "C" fn dc_get_chat_contacts( context: *mut dc_context_t, chat_id: u32, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let arr = dc_array_t::from(chat::get_chat_contacts(context, chat_id)); @@ -580,8 +719,10 @@ pub unsafe extern "C" fn dc_search_msgs( chat_id: u32, query: *mut libc::c_char, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); - assert!(!query.is_null()); + if context.is_null() || query.is_null() { + return ptr::null_mut(); + } + let context = &*context; let arr = dc_array_t::from(context::dc_search_msgs(context, chat_id, query)); @@ -593,7 +734,10 @@ pub unsafe extern "C" fn dc_get_chat<'a>( context: *mut dc_context_t, chat_id: u32, ) -> *mut dc_chat_t<'a> { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; match chat::Chat::load_from_db(context, chat_id) { @@ -608,8 +752,10 @@ pub unsafe extern "C" fn dc_create_group_chat( verified: libc::c_int, name: *mut libc::c_char, ) -> u32 { - assert!(!context.is_null()); - assert!(!name.is_null()); + if context.is_null() || name.is_null() { + return 0; + } + let context = &*context; let verified = if let Some(s) = contact::VerifiedStatus::from_i32(verified) { @@ -628,7 +774,10 @@ pub unsafe extern "C" fn dc_is_contact_in_chat( chat_id: u32, contact_id: u32, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::is_contact_in_chat(context, chat_id, contact_id) @@ -640,7 +789,10 @@ pub unsafe extern "C" fn dc_add_contact_to_chat( chat_id: u32, contact_id: u32, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::add_contact_to_chat(context, chat_id, contact_id) @@ -652,7 +804,10 @@ pub unsafe extern "C" fn dc_remove_contact_from_chat( chat_id: u32, contact_id: u32, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; chat::remove_contact_from_chat(context, chat_id, contact_id) @@ -666,9 +821,10 @@ pub unsafe extern "C" fn dc_set_chat_name( chat_id: u32, name: *mut libc::c_char, ) -> libc::c_int { - assert!(!context.is_null()); - assert!(!name.is_null()); - assert!(chat_id > constants::DC_CHAT_ID_LAST_SPECIAL as u32); + if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 || name.is_null() { + return 0; + } + let context = &*context; chat::set_chat_name(context, chat_id, as_str(name)) @@ -682,8 +838,10 @@ pub unsafe extern "C" fn dc_set_chat_profile_image( chat_id: u32, image: *mut libc::c_char, ) -> libc::c_int { - assert!(!context.is_null()); - assert!(chat_id > constants::DC_CHAT_ID_LAST_SPECIAL as u32); + if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 { + return 0; + } + let context = &*context; chat::set_chat_profile_image(context, chat_id, as_str(image)) @@ -696,7 +854,10 @@ pub unsafe extern "C" fn dc_get_msg_info( context: *mut dc_context_t, msg_id: u32, ) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return dc_strdup(ptr::null()); + } + let context = &*context; message::dc_get_msg_info(context, msg_id) @@ -707,7 +868,10 @@ pub unsafe extern "C" fn dc_get_mime_headers( context: *mut dc_context_t, msg_id: u32, ) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); // NULL explicitly defined as "no mime headers" + } + let context = &*context; message::dc_get_mime_headers(context, msg_id) @@ -719,9 +883,10 @@ pub unsafe extern "C" fn dc_delete_msgs( msg_ids: *const u32, msg_cnt: libc::c_int, ) { - assert!(!context.is_null()); - assert!(!msg_ids.is_null()); - assert!(msg_cnt >= 0); + if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 { + return; + } + let context = &*context; message::dc_delete_msgs(context, msg_ids, msg_cnt) @@ -734,10 +899,14 @@ pub unsafe extern "C" fn dc_forward_msgs( msg_cnt: libc::c_int, chat_id: u32, ) { - assert!(!context.is_null()); - assert!(!msg_ids.is_null()); - assert!(msg_cnt >= 0); - assert!(chat_id > constants::DC_CHAT_ID_LAST_SPECIAL as u32); + if context.is_null() + || msg_ids.is_null() + || msg_cnt <= 0 + || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 + { + return; + } + let context = &*context; chat::forward_msgs(context, msg_ids, msg_cnt, chat_id) @@ -745,7 +914,10 @@ pub unsafe extern "C" fn dc_forward_msgs( #[no_mangle] pub unsafe extern "C" fn dc_marknoticed_contact(context: *mut dc_context_t, contact_id: u32) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; Contact::mark_noticed(context, contact_id) @@ -757,9 +929,10 @@ pub unsafe extern "C" fn dc_markseen_msgs( msg_ids: *const u32, msg_cnt: libc::c_int, ) { - assert!(!context.is_null()); - assert!(!msg_ids.is_null()); - assert!(msg_cnt >= 0); + if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 { + return; + } + let context = &*context; message::dc_markseen_msgs(context, msg_ids, msg_cnt as usize); @@ -772,9 +945,9 @@ pub unsafe extern "C" fn dc_star_msgs( msg_cnt: libc::c_int, star: libc::c_int, ) { - assert!(!context.is_null()); - assert!(!msg_ids.is_null()); - assert!(msg_cnt >= 0); + if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 { + return; + } let context = &*context; @@ -786,7 +959,10 @@ pub unsafe extern "C" fn dc_get_msg<'a>( context: *mut dc_context_t, msg_id: u32, ) -> *mut dc_msg_t<'a> { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; message::dc_get_msg(context, msg_id).into_raw() @@ -794,7 +970,10 @@ pub unsafe extern "C" fn dc_get_msg<'a>( #[no_mangle] pub unsafe extern "C" fn dc_may_be_valid_addr(addr: *mut libc::c_char) -> libc::c_int { - assert!(!addr.is_null()); + if addr.is_null() { + return 0; + } + contact::may_be_valid_addr(as_str(addr)) as libc::c_int } @@ -803,8 +982,10 @@ pub unsafe extern "C" fn dc_lookup_contact_id_by_addr( context: *mut dc_context_t, addr: *mut libc::c_char, ) -> u32 { - assert!(!context.is_null()); - assert!(!addr.is_null()); + if context.is_null() || addr.is_null() { + return 0; + } + let context = &*context; Contact::lookup_id_by_addr(context, as_str(addr)) @@ -816,8 +997,9 @@ pub unsafe extern "C" fn dc_create_contact( name: *mut libc::c_char, addr: *mut libc::c_char, ) -> u32 { - assert!(!context.is_null()); - assert!(!addr.is_null()); + if context.is_null() || addr.is_null() { + return 0; + } let context = &*context; @@ -834,8 +1016,10 @@ pub unsafe extern "C" fn dc_add_address_book( context: *mut dc_context_t, addr_book: *mut libc::c_char, ) -> libc::c_int { - assert!(!context.is_null()); - assert!(!addr_book.is_null()); + if context.is_null() || addr_book.is_null() { + return 0; + } + let context = &*context; match Contact::add_address_book(context, as_str(addr_book)) { @@ -850,7 +1034,10 @@ pub unsafe extern "C" fn dc_get_contacts( flags: u32, query: *mut libc::c_char, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let query = if query.is_null() { @@ -867,7 +1054,10 @@ pub unsafe extern "C" fn dc_get_contacts( #[no_mangle] pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context_t) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; Contact::get_blocked_cnt(context) as libc::c_int @@ -877,7 +1067,10 @@ pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context_t) -> libc: pub unsafe extern "C" fn dc_get_blocked_contacts( context: *mut dc_context_t, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; Box::into_raw(Box::new(dc_array_t::from(Contact::get_all_blocked( @@ -891,7 +1084,10 @@ pub unsafe extern "C" fn dc_block_contact( contact_id: u32, block: libc::c_int, ) { - assert!(!context.is_null()); + if context.is_null() || contact_id <= constants::DC_CONTACT_ID_LAST_SPECIAL as u32 { + return; + } + let context = &*context; if block == 0 { @@ -906,7 +1102,10 @@ pub unsafe extern "C" fn dc_get_contact_encrinfo( context: *mut dc_context_t, contact_id: u32, ) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return dc_strdup(ptr::null()); + } + let context = &*context; Contact::get_encrinfo(context, contact_id) @@ -922,7 +1121,10 @@ pub unsafe extern "C" fn dc_delete_contact( context: *mut dc_context_t, contact_id: u32, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() || contact_id <= constants::DC_CONTACT_ID_LAST_SPECIAL as u32 { + return 0; + } + let context = &*context; match Contact::delete(context, contact_id) { @@ -936,7 +1138,10 @@ pub unsafe extern "C" fn dc_get_contact<'a>( context: *mut dc_context_t, contact_id: u32, ) -> *mut dc_contact_t<'a> { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; Contact::get_by_id(context, contact_id) @@ -951,7 +1156,10 @@ pub unsafe extern "C" fn dc_imex( param1: *mut libc::c_char, param2: *mut libc::c_char, ) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; dc_imex::dc_imex(context, what, param1, param2) @@ -962,8 +1170,10 @@ pub unsafe extern "C" fn dc_imex_has_backup( context: *mut dc_context_t, dir: *mut libc::c_char, ) -> *mut libc::c_char { - assert!(!context.is_null()); - assert!(!dir.is_null()); + if context.is_null() || dir.is_null() { + return 0; + } + let context = &*context; dc_imex::dc_imex_has_backup(context, dir) @@ -971,7 +1181,10 @@ pub unsafe extern "C" fn dc_imex_has_backup( #[no_mangle] pub unsafe extern "C" fn dc_initiate_key_transfer(context: *mut dc_context_t) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; dc_imex::dc_initiate_key_transfer(context) @@ -983,8 +1196,13 @@ pub unsafe extern "C" fn dc_continue_key_transfer( msg_id: u32, setup_code: *mut libc::c_char, ) -> libc::c_int { - assert!(!context.is_null()); - assert!(!setup_code.is_null()); + if context.is_null() + || msg_id <= constants::DC_MSG_ID_LAST_SPECIAL as u32 + || setup_code.is_null() + { + return 0; + } + let context = &*context; dc_imex::dc_continue_key_transfer(context, msg_id, setup_code) @@ -992,7 +1210,10 @@ pub unsafe extern "C" fn dc_continue_key_transfer( #[no_mangle] pub unsafe extern "C" fn dc_stop_ongoing_process(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; configure::dc_stop_ongoing_process(context) @@ -1003,8 +1224,10 @@ pub unsafe extern "C" fn dc_check_qr( context: *mut dc_context_t, qr: *mut libc::c_char, ) -> *mut dc_lot_t { - assert!(!context.is_null()); - assert!(!qr.is_null()); + if context.is_null() || qr.is_null() { + return ptr::null_mut(); + } + let context = &*context; let lot = qr::check_qr(context, as_str(qr)); @@ -1016,7 +1239,10 @@ pub unsafe extern "C" fn dc_get_securejoin_qr( context: *mut dc_context_t, chat_id: u32, ) -> *mut libc::c_char { - assert!(!context.is_null()); + if context.is_null() { + return dc_strdup(ptr::null()); + } + let context = &*context; dc_securejoin::dc_get_securejoin_qr(context, chat_id) @@ -1027,8 +1253,10 @@ pub unsafe extern "C" fn dc_join_securejoin( context: *mut dc_context_t, qr: *mut libc::c_char, ) -> u32 { - assert!(!context.is_null()); - assert!(!qr.is_null()); + if context.is_null() || qr.is_null() { + return 0; + } + let context = &*context; dc_securejoin::dc_join_securejoin(context, qr) @@ -1040,7 +1268,10 @@ pub unsafe extern "C" fn dc_send_locations_to_chat( chat_id: u32, seconds: libc::c_int, ) { - assert!(!context.is_null()); + if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 || seconds < 0 { + return; + } + let context = &*context; location::send_locations_to_chat(context, chat_id, seconds as i64) @@ -1051,7 +1282,10 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat( context: *mut dc_context_t, chat_id: u32, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; location::is_sending_locations_to_chat(context, chat_id) as libc::c_int @@ -1064,7 +1298,10 @@ pub unsafe extern "C" fn dc_set_location( longitude: libc::c_double, accuracy: libc::c_double, ) -> libc::c_int { - assert!(!context.is_null()); + if context.is_null() { + return 0; + } + let context = &*context; location::set(context, latitude, longitude, accuracy) @@ -1078,7 +1315,10 @@ pub unsafe extern "C" fn dc_get_locations( timestamp_begin: i64, timestamp_end: i64, ) -> *mut dc_array::dc_array_t { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let res = location::get_range( @@ -1093,7 +1333,10 @@ pub unsafe extern "C" fn dc_get_locations( #[no_mangle] pub unsafe extern "C" fn dc_delete_all_locations(context: *mut dc_context_t) { - assert!(!context.is_null()); + if context.is_null() { + return; + } + let context = &*context; location::delete_all(context).log_err(context, "Failed to delete locations"); @@ -1106,27 +1349,35 @@ pub type dc_array_t = dc_array::dc_array_t; #[no_mangle] pub unsafe extern "C" fn dc_array_unref(a: *mut dc_array::dc_array_t) { - assert!(!a.is_null()); + if a.is_null() { + return; + } Box::from_raw(a); } #[no_mangle] pub unsafe extern "C" fn dc_array_add_id(array: *mut dc_array_t, item: libc::c_uint) { - assert!(!array.is_null()); + if array.is_null() { + return; + } (*array).add_id(item); } #[no_mangle] pub unsafe extern "C" fn dc_array_get_cnt(array: *const dc_array_t) -> libc::size_t { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).len() } #[no_mangle] pub unsafe extern "C" fn dc_array_get_id(array: *const dc_array_t, index: libc::size_t) -> u32 { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_id(index) } @@ -1135,7 +1386,9 @@ pub unsafe extern "C" fn dc_array_get_latitude( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_double { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).latitude } @@ -1144,7 +1397,9 @@ pub unsafe extern "C" fn dc_array_get_longitude( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_double { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).longitude } @@ -1153,7 +1408,9 @@ pub unsafe extern "C" fn dc_array_get_accuracy( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_double { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).accuracy } @@ -1162,7 +1419,9 @@ pub unsafe extern "C" fn dc_array_get_timestamp( array: *const dc_array_t, index: libc::size_t, ) -> i64 { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).timestamp } @@ -1171,7 +1430,9 @@ pub unsafe extern "C" fn dc_array_get_chat_id( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_uint { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).chat_id } @@ -1180,7 +1441,9 @@ pub unsafe extern "C" fn dc_array_get_contact_id( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_uint { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).contact_id } @@ -1189,7 +1452,9 @@ pub unsafe extern "C" fn dc_array_get_msg_id( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_uint { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).msg_id } @@ -1198,7 +1463,9 @@ pub unsafe extern "C" fn dc_array_get_marker( array: *const dc_array_t, index: libc::size_t, ) -> *mut libc::c_char { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } if let Some(s) = &(*array).get_location(index).marker { s.strdup() @@ -1213,7 +1480,9 @@ pub unsafe extern "C" fn dc_array_search_id( needle: libc::c_uint, ret_index: *mut libc::size_t, ) -> libc::c_int { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } if let Some(i) = (*array).search_id(needle) { if !ret_index.is_null() { @@ -1227,7 +1496,9 @@ pub unsafe extern "C" fn dc_array_search_id( #[no_mangle] pub unsafe extern "C" fn dc_array_get_raw(array: *const dc_array_t) -> *const u32 { - assert!(!array.is_null()); + if array.is_null() { + return ptr::null_mut(); + } (*array).as_ptr() } @@ -1241,7 +1512,9 @@ pub unsafe fn dc_array_is_independent( array: *const dc_array_t, index: libc::size_t, ) -> libc::c_int { - assert!(!array.is_null()); + if array.is_null() { + return 0; + } (*array).get_location(index).independent as libc::c_int } @@ -1253,14 +1526,18 @@ pub type dc_chatlist_t<'a> = chatlist::Chatlist<'a>; #[no_mangle] pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist_t) { - assert!(!chatlist.is_null()); + if chatlist.is_null() { + return; + } Box::from_raw(chatlist); } #[no_mangle] pub unsafe extern "C" fn dc_chatlist_get_cnt(chatlist: *mut dc_chatlist_t) -> libc::size_t { - assert!(!chatlist.is_null()); + if chatlist.is_null() { + return 0; + } let list = &*chatlist; list.len() as libc::size_t @@ -1271,7 +1548,9 @@ pub unsafe extern "C" fn dc_chatlist_get_chat_id( chatlist: *mut dc_chatlist_t, index: libc::size_t, ) -> u32 { - assert!(!chatlist.is_null()); + if chatlist.is_null() { + return 0; + } let list = &*chatlist; list.get_chat_id(index as usize) @@ -1282,7 +1561,9 @@ pub unsafe extern "C" fn dc_chatlist_get_msg_id( chatlist: *mut dc_chatlist_t, index: libc::size_t, ) -> u32 { - assert!(!chatlist.is_null()); + if chatlist.is_null() { + return 0; + } let list = &*chatlist; list.get_msg_id(index as usize) @@ -1294,7 +1575,9 @@ pub unsafe extern "C" fn dc_chatlist_get_summary<'a>( index: libc::size_t, chat: *mut dc_chat_t<'a>, ) -> *mut dc_lot_t { - assert!(!chatlist.is_null()); + if chatlist.is_null() { + return ptr::null_mut(); + } let chat = if chat.is_null() { None } else { Some(&*chat) }; let list = &*chatlist; @@ -1307,7 +1590,10 @@ pub unsafe extern "C" fn dc_chatlist_get_summary<'a>( pub unsafe extern "C" fn dc_chatlist_get_context( chatlist: *mut dc_chatlist_t, ) -> *const dc_context_t { - assert!(!chatlist.is_null()); + if chatlist.is_null() { + return ptr::null_mut(); + } + let list = &*chatlist; list.get_context() as *const _ @@ -1320,14 +1606,19 @@ pub type dc_chat_t<'a> = chat::Chat<'a>; #[no_mangle] pub unsafe extern "C" fn dc_chat_unref(chat: *mut dc_chat_t) { - assert!(!chat.is_null()); + if chat.is_null() { + return; + } Box::from_raw(chat); } #[no_mangle] pub unsafe extern "C" fn dc_chat_get_id(chat: *mut dc_chat_t) -> u32 { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.get_id() @@ -1335,7 +1626,10 @@ pub unsafe extern "C" fn dc_chat_get_id(chat: *mut dc_chat_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_type(chat: *mut dc_chat_t) -> libc::c_int { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.get_type() as libc::c_int @@ -1343,7 +1637,10 @@ pub unsafe extern "C" fn dc_chat_get_type(chat: *mut dc_chat_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_name(chat: *mut dc_chat_t) -> *mut libc::c_char { - assert!(!chat.is_null()); + if chat.is_null() { + return dc_strdup(ptr::null()); + } + let chat = &*chat; chat.get_name().strdup() @@ -1351,7 +1648,10 @@ pub unsafe extern "C" fn dc_chat_get_name(chat: *mut dc_chat_t) -> *mut libc::c_ #[no_mangle] pub unsafe extern "C" fn dc_chat_get_subtitle(chat: *mut dc_chat_t) -> *mut libc::c_char { - assert!(!chat.is_null()); + if chat.is_null() { + return dc_strdup(ptr::null()); + } + let chat = &*chat; chat.get_subtitle().strdup() @@ -1359,7 +1659,10 @@ pub unsafe extern "C" fn dc_chat_get_subtitle(chat: *mut dc_chat_t) -> *mut libc #[no_mangle] pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut libc::c_char { - assert!(!chat.is_null()); + if chat.is_null() { + return ptr::null_mut(); // NULL explicitly defined as "no image" + } + let chat = &*chat; match chat.get_profile_image() { @@ -1370,7 +1673,10 @@ pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut #[no_mangle] pub unsafe extern "C" fn dc_chat_get_color(chat: *mut dc_chat_t) -> u32 { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.get_color() @@ -1378,7 +1684,10 @@ pub unsafe extern "C" fn dc_chat_get_color(chat: *mut dc_chat_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_archived(chat: *mut dc_chat_t) -> libc::c_int { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.is_archived() as libc::c_int @@ -1386,7 +1695,10 @@ pub unsafe extern "C" fn dc_chat_get_archived(chat: *mut dc_chat_t) -> libc::c_i #[no_mangle] pub unsafe extern "C" fn dc_chat_is_unpromoted(chat: *mut dc_chat_t) -> libc::c_int { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.is_unpromoted() as libc::c_int @@ -1394,7 +1706,10 @@ pub unsafe extern "C" fn dc_chat_is_unpromoted(chat: *mut dc_chat_t) -> libc::c_ #[no_mangle] pub unsafe extern "C" fn dc_chat_is_self_talk(chat: *mut dc_chat_t) -> libc::c_int { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.is_self_talk() as libc::c_int @@ -1402,7 +1717,10 @@ pub unsafe extern "C" fn dc_chat_is_self_talk(chat: *mut dc_chat_t) -> libc::c_i #[no_mangle] pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_int { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.is_verified() as libc::c_int @@ -1410,7 +1728,10 @@ pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_in #[no_mangle] pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> libc::c_int { - assert!(!chat.is_null()); + if chat.is_null() { + return 0; + } + let chat = &*chat; chat.is_sending_locations() as libc::c_int @@ -1426,7 +1747,10 @@ pub unsafe extern "C" fn dc_msg_new<'a>( context: *mut dc_context_t, viewtype: libc::c_int, ) -> *mut dc_msg_t<'a> { - assert!(!context.is_null()); + if context.is_null() { + return ptr::null_mut(); + } + let context = &*context; let viewtype = from_prim(viewtype).expect(&format!("invalid viewtype = {}", viewtype)); @@ -1435,14 +1759,18 @@ pub unsafe extern "C" fn dc_msg_new<'a>( #[no_mangle] pub unsafe extern "C" fn dc_msg_unref(msg: *mut dc_msg_t) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } Box::from_raw(msg); } #[no_mangle] pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg_t) -> u32 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_id(msg) @@ -1450,7 +1778,9 @@ pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg_t) -> u32 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_from_id(msg) @@ -1458,7 +1788,9 @@ pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg_t) -> u32 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_chat_id(msg) @@ -1466,7 +1798,9 @@ pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_viewtype(msg) @@ -1476,7 +1810,9 @@ pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_get_state(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_state(msg) as libc::c_int @@ -1484,7 +1820,9 @@ pub unsafe extern "C" fn dc_msg_get_state(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_timestamp(msg: *mut dc_msg_t) -> i64 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_timestamp(msg) @@ -1492,7 +1830,9 @@ pub unsafe extern "C" fn dc_msg_get_timestamp(msg: *mut dc_msg_t) -> i64 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_received_timestamp(msg: *mut dc_msg_t) -> i64 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_received_timestamp(msg) @@ -1500,7 +1840,9 @@ pub unsafe extern "C" fn dc_msg_get_received_timestamp(msg: *mut dc_msg_t) -> i6 #[no_mangle] pub unsafe extern "C" fn dc_msg_get_sort_timestamp(msg: *mut dc_msg_t) -> i64 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_sort_timestamp(msg) @@ -1508,7 +1850,9 @@ pub unsafe extern "C" fn dc_msg_get_sort_timestamp(msg: *mut dc_msg_t) -> i64 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg_t) -> *mut libc::c_char { - assert!(!msg.is_null()); + if msg.is_null() { + return dc_strdup(ptr::null()); + } let msg = &*msg; message::dc_msg_get_text(msg) @@ -1516,7 +1860,9 @@ pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg_t) -> *mut libc::c_cha #[no_mangle] pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_char { - assert!(!msg.is_null()); + if msg.is_null() { + return dc_strdup(ptr::null()); + } let msg = &*msg; message::dc_msg_get_file(msg) @@ -1524,7 +1870,9 @@ pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_cha #[no_mangle] pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c_char { - assert!(!msg.is_null()); + if msg.is_null() { + return dc_strdup(ptr::null()); + } let msg = &*msg; message::dc_msg_get_filename(msg) @@ -1532,7 +1880,9 @@ pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c #[no_mangle] pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c_char { - assert!(!msg.is_null()); + if msg.is_null() { + return dc_strdup(ptr::null()); + } let msg = &*msg; message::dc_msg_get_filemime(msg) @@ -1540,7 +1890,9 @@ pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c #[no_mangle] pub unsafe extern "C" fn dc_msg_get_filebytes(msg: *mut dc_msg_t) -> u64 { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_filebytes(msg) @@ -1548,7 +1900,9 @@ pub unsafe extern "C" fn dc_msg_get_filebytes(msg: *mut dc_msg_t) -> u64 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_width(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_width(msg) @@ -1556,7 +1910,9 @@ pub unsafe extern "C" fn dc_msg_get_width(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_height(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_height(msg) @@ -1564,7 +1920,9 @@ pub unsafe extern "C" fn dc_msg_get_height(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_duration(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_duration(msg) @@ -1572,7 +1930,9 @@ pub unsafe extern "C" fn dc_msg_get_duration(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_get_showpadlock(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_get_showpadlock(msg) @@ -1583,7 +1943,9 @@ pub unsafe extern "C" fn dc_msg_get_summary<'a>( msg: *mut dc_msg_t<'a>, chat: *mut dc_chat_t<'a>, ) -> *mut dc_lot_t { - assert!(!msg.is_null()); + if msg.is_null() { + return ptr::null_mut(); + } let chat = if chat.is_null() { None } else { Some(&*chat) }; let msg = &mut *msg; @@ -1597,7 +1959,9 @@ pub unsafe extern "C" fn dc_msg_get_summarytext( msg: *mut dc_msg_t, approx_characters: libc::c_int, ) -> *mut libc::c_char { - assert!(!msg.is_null()); + if msg.is_null() { + return dc_strdup(ptr::null()); + } let msg = &mut *msg; message::dc_msg_get_summarytext(msg, approx_characters.try_into().unwrap()) @@ -1605,7 +1969,9 @@ pub unsafe extern "C" fn dc_msg_get_summarytext( #[no_mangle] pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_has_deviating_timestamp(msg) @@ -1613,7 +1979,9 @@ pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg_t) -> l #[no_mangle] pub unsafe extern "C" fn dc_msg_has_location(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_has_location(msg) as libc::c_int @@ -1621,7 +1989,9 @@ pub unsafe extern "C" fn dc_msg_has_location(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_is_sent(msg) @@ -1629,7 +1999,9 @@ pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_is_starred(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_is_starred(msg).into() @@ -1637,7 +2009,9 @@ pub unsafe extern "C" fn dc_msg_is_starred(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_is_forwarded(msg) @@ -1645,7 +2019,9 @@ pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_is_info(msg) @@ -1653,7 +2029,9 @@ pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_is_increation(msg) @@ -1661,7 +2039,9 @@ pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_int { - assert!(!msg.is_null()); + if msg.is_null() { + return 0; + } let msg = &*msg; message::dc_msg_is_setupmessage(msg) as libc::c_int @@ -1669,7 +2049,9 @@ pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_i #[no_mangle] pub unsafe extern "C" fn dc_msg_get_setupcodebegin(msg: *mut dc_msg_t) -> *mut libc::c_char { - assert!(!msg.is_null()); + if msg.is_null() { + return dc_strdup(ptr::null()); + } let msg = &*msg; message::dc_msg_get_setupcodebegin(msg) @@ -1677,7 +2059,9 @@ pub unsafe extern "C" fn dc_msg_get_setupcodebegin(msg: *mut dc_msg_t) -> *mut l #[no_mangle] pub unsafe extern "C" fn dc_msg_set_text(msg: *mut dc_msg_t, text: *mut libc::c_char) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } let msg = &mut *msg; // TODO: {text} equal to NULL is treated as "", which is strange. Does anyone rely on it? @@ -1690,7 +2074,9 @@ pub unsafe extern "C" fn dc_msg_set_file( file: *mut libc::c_char, filemime: *mut libc::c_char, ) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } let msg = &mut *msg; message::dc_msg_set_file(msg, file, filemime) @@ -1702,7 +2088,9 @@ pub unsafe extern "C" fn dc_msg_set_dimension( width: libc::c_int, height: libc::c_int, ) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } let msg = &mut *msg; message::dc_msg_set_dimension(msg, width, height) @@ -1710,7 +2098,9 @@ pub unsafe extern "C" fn dc_msg_set_dimension( #[no_mangle] pub unsafe extern "C" fn dc_msg_set_duration(msg: *mut dc_msg_t, duration: libc::c_int) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } let msg = &mut *msg; message::dc_msg_set_duration(msg, duration) @@ -1722,7 +2112,9 @@ pub unsafe extern "C" fn dc_msg_set_location( latitude: libc::c_double, longitude: libc::c_double, ) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } let msg = &mut *msg; message::dc_msg_set_location(msg, latitude, longitude) @@ -1735,7 +2127,9 @@ pub unsafe extern "C" fn dc_msg_latefiling_mediasize( height: libc::c_int, duration: libc::c_int, ) { - assert!(!msg.is_null()); + if msg.is_null() { + return; + } let msg = &mut *msg; message::dc_msg_latefiling_mediasize(msg, width, height, duration) @@ -1748,13 +2142,19 @@ pub type dc_contact_t<'a> = contact::Contact<'a>; #[no_mangle] pub unsafe extern "C" fn dc_contact_unref(contact: *mut dc_contact_t) { - assert!(!contact.is_null()); + if contact.is_null() { + return; + } + Box::from_raw(contact); } #[no_mangle] pub unsafe extern "C" fn dc_contact_get_id(contact: *mut dc_contact_t) -> u32 { - assert!(!contact.is_null()); + if contact.is_null() { + return 0; + } + let contact = &*contact; contact.get_id() @@ -1762,7 +2162,10 @@ pub unsafe extern "C" fn dc_contact_get_id(contact: *mut dc_contact_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_contact_get_addr(contact: *mut dc_contact_t) -> *mut libc::c_char { - assert!(!contact.is_null()); + if contact.is_null() { + return dc_strdup(ptr::null()); + } + let contact = &*contact; contact.get_addr().strdup() @@ -1770,7 +2173,10 @@ pub unsafe extern "C" fn dc_contact_get_addr(contact: *mut dc_contact_t) -> *mut #[no_mangle] pub unsafe extern "C" fn dc_contact_get_name(contact: *mut dc_contact_t) -> *mut libc::c_char { - assert!(!contact.is_null()); + if contact.is_null() { + return dc_strdup(ptr::null()); + } + let contact = &*contact; contact.get_name().strdup() @@ -1780,7 +2186,10 @@ pub unsafe extern "C" fn dc_contact_get_name(contact: *mut dc_contact_t) -> *mut pub unsafe extern "C" fn dc_contact_get_display_name( contact: *mut dc_contact_t, ) -> *mut libc::c_char { - assert!(!contact.is_null()); + if contact.is_null() { + return dc_strdup(ptr::null()); + } + let contact = &*contact; contact.get_display_name().strdup() @@ -1790,7 +2199,10 @@ pub unsafe extern "C" fn dc_contact_get_display_name( pub unsafe extern "C" fn dc_contact_get_name_n_addr( contact: *mut dc_contact_t, ) -> *mut libc::c_char { - assert!(!contact.is_null()); + if contact.is_null() { + return dc_strdup(ptr::null()); + } + let contact = &*contact; contact.get_name_n_addr().strdup() @@ -1800,7 +2212,10 @@ pub unsafe extern "C" fn dc_contact_get_name_n_addr( pub unsafe extern "C" fn dc_contact_get_first_name( contact: *mut dc_contact_t, ) -> *mut libc::c_char { - assert!(!contact.is_null()); + if contact.is_null() { + return dc_strdup(ptr::null()); + } + let contact = &*contact; contact.get_first_name().strdup() @@ -1810,7 +2225,10 @@ pub unsafe extern "C" fn dc_contact_get_first_name( pub unsafe extern "C" fn dc_contact_get_profile_image( contact: *mut dc_contact_t, ) -> *mut libc::c_char { - assert!(!contact.is_null()); + if contact.is_null() { + return ptr::null_mut(); // NULL explicitly defined as "no profile image" + } + let contact = &*contact; contact @@ -1821,7 +2239,10 @@ pub unsafe extern "C" fn dc_contact_get_profile_image( #[no_mangle] pub unsafe extern "C" fn dc_contact_get_color(contact: *mut dc_contact_t) -> u32 { - assert!(!contact.is_null()); + if contact.is_null() { + return 0; + } + let contact = &*contact; contact.get_color() @@ -1829,7 +2250,10 @@ pub unsafe extern "C" fn dc_contact_get_color(contact: *mut dc_contact_t) -> u32 #[no_mangle] pub unsafe extern "C" fn dc_contact_is_blocked(contact: *mut dc_contact_t) -> libc::c_int { - assert!(!contact.is_null()); + if contact.is_null() { + return 0; + } + let contact = &*contact; contact.is_blocked() as libc::c_int @@ -1837,7 +2261,10 @@ pub unsafe extern "C" fn dc_contact_is_blocked(contact: *mut dc_contact_t) -> li #[no_mangle] pub unsafe extern "C" fn dc_contact_is_verified(contact: *mut dc_contact_t) -> libc::c_int { - assert!(!contact.is_null()); + if contact.is_null() { + return 0; + } + let contact = &*contact; contact.is_verified() as libc::c_int @@ -1850,14 +2277,18 @@ pub type dc_lot_t = lot::Lot; #[no_mangle] pub unsafe extern "C" fn dc_lot_unref(lot: *mut dc_lot_t) { - assert!(!lot.is_null()); + if lot.is_null() { + return; + } Box::from_raw(lot); } #[no_mangle] pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_char { - assert!(!lot.is_null()); + if lot.is_null() { + return ptr::mut_null(); // NULL explicitly defined as "there is no such text" + } let lot = &*lot; strdup_opt(lot.get_text1()) @@ -1865,7 +2296,9 @@ pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_ch #[no_mangle] pub unsafe extern "C" fn dc_lot_get_text2(lot: *mut dc_lot_t) -> *mut libc::c_char { - assert!(!lot.is_null()); + if lot.is_null() { + return ptr::mut_null(); // NULL explicitly defined as "there is no such text" + } let lot = &*lot; strdup_opt(lot.get_text2()) @@ -1873,7 +2306,9 @@ pub unsafe extern "C" fn dc_lot_get_text2(lot: *mut dc_lot_t) -> *mut libc::c_ch #[no_mangle] pub unsafe extern "C" fn dc_lot_get_text1_meaning(lot: *mut dc_lot_t) -> libc::c_int { - assert!(!lot.is_null()); + if lot.is_null() { + return 0; + } let lot = &*lot; lot.get_text1_meaning() as libc::c_int @@ -1881,7 +2316,9 @@ pub unsafe extern "C" fn dc_lot_get_text1_meaning(lot: *mut dc_lot_t) -> libc::c #[no_mangle] pub unsafe extern "C" fn dc_lot_get_state(lot: *mut dc_lot_t) -> libc::c_int { - assert!(!lot.is_null()); + if lot.is_null() { + return 0; + } let lot = &*lot; lot.get_state().to_i64().expect("impossible") as libc::c_int @@ -1889,7 +2326,9 @@ pub unsafe extern "C" fn dc_lot_get_state(lot: *mut dc_lot_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_lot_get_id(lot: *mut dc_lot_t) -> u32 { - assert!(!lot.is_null()); + if lot.is_null() { + return 0; + } let lot = &*lot; lot.get_id() @@ -1897,7 +2336,9 @@ pub unsafe extern "C" fn dc_lot_get_id(lot: *mut dc_lot_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_lot_get_timestamp(lot: *mut dc_lot_t) -> i64 { - assert!(!lot.is_null()); + if lot.is_null() { + return 0; + } let lot = &*lot; lot.get_timestamp() From 010ac6a6acdf7bfa6e7d5fcb0a4770095b24cbce Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 28 Aug 2019 18:24:01 +0200 Subject: [PATCH 2/3] print message to stderr on careless ffi usage --- deltachat-ffi/src/lib.rs | 173 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index a03d6a2f7..f5d09a2dd 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -60,6 +60,7 @@ pub unsafe extern "C" fn dc_context_new( #[no_mangle] pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_context_unref()"); return; } @@ -71,6 +72,7 @@ pub unsafe extern "C" fn dc_context_unref(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_get_userdata(context: *mut dc_context_t) -> *mut libc::c_void { if context.is_null() { + eprintln!("ignoring careless call to dc_get_userdata()"); return ptr::null_mut(); } @@ -86,6 +88,7 @@ pub unsafe extern "C" fn dc_open( blobdir: *mut libc::c_char, ) -> libc::c_int { if context.is_null() || dbfile.is_null() { + eprintln!("ignoring careless call to dc_open()"); return 0; } @@ -103,6 +106,7 @@ pub unsafe extern "C" fn dc_open( #[no_mangle] pub unsafe extern "C" fn dc_close(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_close()"); return; } @@ -113,6 +117,7 @@ pub unsafe extern "C" fn dc_close(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_is_open(context: *mut dc_context_t) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_is_open()"); return 0; } @@ -123,6 +128,7 @@ pub unsafe extern "C" fn dc_is_open(context: *mut dc_context_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_get_blobdir(context: *mut dc_context_t) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_blobdir()"); return dc_strdup(ptr::null()); } @@ -138,6 +144,7 @@ pub unsafe extern "C" fn dc_set_config( value: *mut libc::c_char, ) -> libc::c_int { if context.is_null() || key.is_null() { + eprintln!("ignoring careless call to dc_set_config()"); return 0; } @@ -155,6 +162,7 @@ pub unsafe extern "C" fn dc_get_config( key: *mut libc::c_char, ) -> *mut libc::c_char { if context.is_null() || key.is_null() { + eprintln!("ignoring careless call to dc_get_config()"); return dc_strdup(ptr::null()); } @@ -170,6 +178,7 @@ pub unsafe extern "C" fn dc_get_config( #[no_mangle] pub unsafe extern "C" fn dc_get_info(context: *mut dc_context_t) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_info()"); return dc_strdup(ptr::null()); } @@ -185,6 +194,7 @@ pub unsafe extern "C" fn dc_get_oauth2_url( redirect: *mut libc::c_char, ) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_oauth2_url()"); return ptr::null_mut(); // NULL explicitly defined as "unknown" } @@ -205,6 +215,7 @@ pub unsafe extern "C" fn dc_get_version_str() -> *mut libc::c_char { #[no_mangle] pub unsafe extern "C" fn dc_configure(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_configure()"); return; } @@ -216,6 +227,7 @@ pub unsafe extern "C" fn dc_configure(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_is_configured()"); return 0; } @@ -227,6 +239,7 @@ pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c #[no_mangle] pub unsafe extern "C" fn dc_perform_imap_jobs(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_imap_jobs()"); return; } @@ -238,6 +251,7 @@ pub unsafe extern "C" fn dc_perform_imap_jobs(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_imap_fetch(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_imap_fetch()"); return; } @@ -249,6 +263,7 @@ pub unsafe extern "C" fn dc_perform_imap_fetch(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_imap_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_imap_idle()"); return; } @@ -260,6 +275,7 @@ pub unsafe extern "C" fn dc_perform_imap_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_imap_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_interrupt_imap_idle()"); return; } @@ -271,6 +287,7 @@ pub unsafe extern "C" fn dc_interrupt_imap_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_mvbox_fetch(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_mvbox_fetch()"); return; } @@ -282,6 +299,7 @@ pub unsafe extern "C" fn dc_perform_mvbox_fetch(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_mvbox_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_mvbox_idle()"); return; } @@ -293,6 +311,7 @@ pub unsafe extern "C" fn dc_perform_mvbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_mvbox_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_interrupt_mvbox_idle()"); return; } @@ -304,6 +323,7 @@ pub unsafe extern "C" fn dc_interrupt_mvbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_sentbox_fetch(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_sentbox_fetch()"); return; } @@ -315,6 +335,7 @@ pub unsafe extern "C" fn dc_perform_sentbox_fetch(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_sentbox_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_sentbox_idle()"); return; } @@ -326,6 +347,7 @@ pub unsafe extern "C" fn dc_perform_sentbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_sentbox_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_interrupt_sentbox_idle()"); return; } @@ -337,6 +359,7 @@ pub unsafe extern "C" fn dc_interrupt_sentbox_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_smtp_jobs(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_smtp_jobs()"); return; } @@ -348,6 +371,7 @@ pub unsafe extern "C" fn dc_perform_smtp_jobs(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_perform_smtp_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_perform_smtp_idle()"); return; } @@ -359,6 +383,7 @@ pub unsafe extern "C" fn dc_perform_smtp_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_interrupt_smtp_idle(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_interrupt_smtp_idle()"); return; } @@ -370,6 +395,7 @@ pub unsafe extern "C" fn dc_interrupt_smtp_idle(context: *mut dc_context_t) { #[no_mangle] pub unsafe extern "C" fn dc_maybe_network(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_maybe_network()"); return; } @@ -386,6 +412,7 @@ pub unsafe extern "C" fn dc_get_chatlist<'a>( query_id: u32, ) -> *mut dc_chatlist_t<'a> { if context.is_null() { + eprintln!("ignoring careless call to dc_get_chatlist()"); return ptr::null_mut(); } @@ -406,6 +433,7 @@ pub unsafe extern "C" fn dc_get_chatlist<'a>( #[no_mangle] pub unsafe extern "C" fn dc_create_chat_by_msg_id(context: *mut dc_context_t, msg_id: u32) -> u32 { if context.is_null() { + eprintln!("ignoring careless call to dc_create_chat_by_msg_id()"); return 0; } @@ -420,6 +448,7 @@ pub unsafe extern "C" fn dc_create_chat_by_contact_id( contact_id: u32, ) -> u32 { if context.is_null() { + eprintln!("ignoring careless call to dc_create_chat_by_contact_id()"); return 0; } @@ -435,6 +464,7 @@ pub unsafe extern "C" fn dc_get_chat_id_by_contact_id( contact_id: u32, ) -> u32 { if context.is_null() { + eprintln!("ignoring careless call to dc_get_chat_id_by_contact_id()"); return 0; } @@ -451,6 +481,7 @@ pub unsafe extern "C" fn dc_prepare_msg( msg: *mut dc_msg_t, ) -> u32 { if context.is_null() || chat_id == 0 || msg.is_null() { + eprintln!("ignoring careless call to dc_prepare_msg()"); return 0; } @@ -468,6 +499,7 @@ pub unsafe extern "C" fn dc_send_msg( msg: *mut dc_msg_t, ) -> u32 { if context.is_null() || chat_id == 0 || msg.is_null() { + eprintln!("ignoring careless call to dc_send_msg()"); return 0; } @@ -484,6 +516,7 @@ pub unsafe extern "C" fn dc_send_text_msg( text_to_send: *mut libc::c_char, ) -> u32 { if context.is_null() || text_to_send.is_null() { + eprintln!("ignoring careless call to dc_send_text_msg()"); return 0; } @@ -501,6 +534,7 @@ pub unsafe extern "C" fn dc_set_draft( msg: *mut dc_msg_t, ) { if context.is_null() { + eprintln!("ignoring careless call to dc_set_draft()"); return; } @@ -516,6 +550,7 @@ pub unsafe extern "C" fn dc_get_draft<'a>( chat_id: u32, ) -> *mut dc_msg_t<'a> { if context.is_null() { + eprintln!("ignoring careless call to dc_get_draft()"); return ptr::null_mut(); // NULL explicitly defined as "no draft" } @@ -532,6 +567,7 @@ pub unsafe extern "C" fn dc_get_chat_msgs( marker1before: u32, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_chat_msgs()"); return ptr::null_mut(); } @@ -544,6 +580,7 @@ pub unsafe extern "C" fn dc_get_chat_msgs( #[no_mangle] pub unsafe extern "C" fn dc_get_msg_cnt(context: *mut dc_context_t, chat_id: u32) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_get_msg_cnt()"); return 0; } @@ -558,6 +595,7 @@ pub unsafe extern "C" fn dc_get_fresh_msg_cnt( chat_id: u32, ) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_get_fresh_msg_cnt()"); return 0; } @@ -571,6 +609,7 @@ pub unsafe extern "C" fn dc_get_fresh_msgs( context: *mut dc_context_t, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_fresh_msgs()"); return ptr::null_mut(); } @@ -583,6 +622,7 @@ pub unsafe extern "C" fn dc_get_fresh_msgs( #[no_mangle] pub unsafe extern "C" fn dc_marknoticed_chat(context: *mut dc_context_t, chat_id: u32) { if context.is_null() { + eprintln!("ignoring careless call to dc_marknoticed_chat()"); return; } @@ -594,6 +634,7 @@ pub unsafe extern "C" fn dc_marknoticed_chat(context: *mut dc_context_t, chat_id #[no_mangle] pub unsafe extern "C" fn dc_marknoticed_all_chats(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_marknoticed_all_chats()"); return; } @@ -619,6 +660,7 @@ pub unsafe extern "C" fn dc_get_chat_media( or_msg_type3: libc::c_int, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_chat_media()"); return ptr::null_mut(); } @@ -650,6 +692,7 @@ pub unsafe extern "C" fn dc_get_next_media( or_msg_type3: libc::c_int, ) -> u32 { if context.is_null() { + eprintln!("ignoring careless call to dc_get_next_media()"); return 0; } @@ -671,6 +714,7 @@ pub unsafe extern "C" fn dc_archive_chat( archive: libc::c_int, ) { if context.is_null() { + eprintln!("ignoring careless call to dc_archive_chat()"); return; } @@ -690,6 +734,7 @@ pub unsafe extern "C" fn dc_archive_chat( #[no_mangle] pub unsafe extern "C" fn dc_delete_chat(context: *mut dc_context_t, chat_id: u32) { if context.is_null() { + eprintln!("ignoring careless call to dc_delete_chat()"); return; } @@ -704,6 +749,7 @@ pub unsafe extern "C" fn dc_get_chat_contacts( chat_id: u32, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_chat_contacts()"); return ptr::null_mut(); } @@ -720,6 +766,7 @@ pub unsafe extern "C" fn dc_search_msgs( query: *mut libc::c_char, ) -> *mut dc_array::dc_array_t { if context.is_null() || query.is_null() { + eprintln!("ignoring careless call to dc_search_msgs()"); return ptr::null_mut(); } @@ -735,6 +782,7 @@ pub unsafe extern "C" fn dc_get_chat<'a>( chat_id: u32, ) -> *mut dc_chat_t<'a> { if context.is_null() { + eprintln!("ignoring careless call to dc_get_chat()"); return ptr::null_mut(); } @@ -753,6 +801,7 @@ pub unsafe extern "C" fn dc_create_group_chat( name: *mut libc::c_char, ) -> u32 { if context.is_null() || name.is_null() { + eprintln!("ignoring careless call to dc_create_group_chat()"); return 0; } @@ -775,6 +824,7 @@ pub unsafe extern "C" fn dc_is_contact_in_chat( contact_id: u32, ) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_is_contact_in_chat()"); return 0; } @@ -790,6 +840,7 @@ pub unsafe extern "C" fn dc_add_contact_to_chat( contact_id: u32, ) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_add_contact_to_chat()"); return 0; } @@ -805,6 +856,7 @@ pub unsafe extern "C" fn dc_remove_contact_from_chat( contact_id: u32, ) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_remove_contact_from_chat()"); return 0; } @@ -822,6 +874,7 @@ pub unsafe extern "C" fn dc_set_chat_name( name: *mut libc::c_char, ) -> libc::c_int { if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 || name.is_null() { + eprintln!("ignoring careless call to dc_set_chat_name()"); return 0; } @@ -839,6 +892,7 @@ pub unsafe extern "C" fn dc_set_chat_profile_image( image: *mut libc::c_char, ) -> libc::c_int { if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 { + eprintln!("ignoring careless call to dc_set_chat_profile_image()"); return 0; } @@ -855,6 +909,7 @@ pub unsafe extern "C" fn dc_get_msg_info( msg_id: u32, ) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_msg_info()"); return dc_strdup(ptr::null()); } @@ -869,6 +924,7 @@ pub unsafe extern "C" fn dc_get_mime_headers( msg_id: u32, ) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_mime_headers()"); return ptr::null_mut(); // NULL explicitly defined as "no mime headers" } @@ -884,6 +940,7 @@ pub unsafe extern "C" fn dc_delete_msgs( msg_cnt: libc::c_int, ) { if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 { + eprintln!("ignoring careless call to dc_delete_msgs()"); return; } @@ -904,6 +961,7 @@ pub unsafe extern "C" fn dc_forward_msgs( || msg_cnt <= 0 || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 { + eprintln!("ignoring careless call to dc_forward_msgs()"); return; } @@ -915,6 +973,7 @@ pub unsafe extern "C" fn dc_forward_msgs( #[no_mangle] pub unsafe extern "C" fn dc_marknoticed_contact(context: *mut dc_context_t, contact_id: u32) { if context.is_null() { + eprintln!("ignoring careless call to dc_marknoticed_contact()"); return; } @@ -930,6 +989,7 @@ pub unsafe extern "C" fn dc_markseen_msgs( msg_cnt: libc::c_int, ) { if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 { + eprintln!("ignoring careless call to dc_markseen_msgs()"); return; } @@ -946,6 +1006,7 @@ pub unsafe extern "C" fn dc_star_msgs( star: libc::c_int, ) { if context.is_null() || msg_ids.is_null() || msg_cnt <= 0 { + eprintln!("ignoring careless call to dc_star_msgs()"); return; } @@ -960,6 +1021,7 @@ pub unsafe extern "C" fn dc_get_msg<'a>( msg_id: u32, ) -> *mut dc_msg_t<'a> { if context.is_null() { + eprintln!("ignoring careless call to dc_get_msg()"); return ptr::null_mut(); } @@ -971,6 +1033,7 @@ pub unsafe extern "C" fn dc_get_msg<'a>( #[no_mangle] pub unsafe extern "C" fn dc_may_be_valid_addr(addr: *mut libc::c_char) -> libc::c_int { if addr.is_null() { + eprintln!("ignoring careless call to dc_may_be_valid_addr()"); return 0; } @@ -983,6 +1046,7 @@ pub unsafe extern "C" fn dc_lookup_contact_id_by_addr( addr: *mut libc::c_char, ) -> u32 { if context.is_null() || addr.is_null() { + eprintln!("ignoring careless call to dc_lookup_contact_id_by_addr()"); return 0; } @@ -998,6 +1062,7 @@ pub unsafe extern "C" fn dc_create_contact( addr: *mut libc::c_char, ) -> u32 { if context.is_null() || addr.is_null() { + eprintln!("ignoring careless call to dc_create_contact()"); return 0; } @@ -1017,6 +1082,7 @@ pub unsafe extern "C" fn dc_add_address_book( addr_book: *mut libc::c_char, ) -> libc::c_int { if context.is_null() || addr_book.is_null() { + eprintln!("ignoring careless call to dc_add_address_book()"); return 0; } @@ -1035,6 +1101,7 @@ pub unsafe extern "C" fn dc_get_contacts( query: *mut libc::c_char, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_contacts()"); return ptr::null_mut(); } @@ -1055,6 +1122,7 @@ pub unsafe extern "C" fn dc_get_contacts( #[no_mangle] pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context_t) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_get_blocked_cnt()"); return 0; } @@ -1068,6 +1136,7 @@ pub unsafe extern "C" fn dc_get_blocked_contacts( context: *mut dc_context_t, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_blocked_contacts()"); return ptr::null_mut(); } @@ -1085,6 +1154,7 @@ pub unsafe extern "C" fn dc_block_contact( block: libc::c_int, ) { if context.is_null() || contact_id <= constants::DC_CONTACT_ID_LAST_SPECIAL as u32 { + eprintln!("ignoring careless call to dc_block_contact()"); return; } @@ -1103,6 +1173,7 @@ pub unsafe extern "C" fn dc_get_contact_encrinfo( contact_id: u32, ) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_contact_encrinfo()"); return dc_strdup(ptr::null()); } @@ -1122,6 +1193,7 @@ pub unsafe extern "C" fn dc_delete_contact( contact_id: u32, ) -> libc::c_int { if context.is_null() || contact_id <= constants::DC_CONTACT_ID_LAST_SPECIAL as u32 { + eprintln!("ignoring careless call to dc_delete_contact()"); return 0; } @@ -1139,6 +1211,7 @@ pub unsafe extern "C" fn dc_get_contact<'a>( contact_id: u32, ) -> *mut dc_contact_t<'a> { if context.is_null() { + eprintln!("ignoring careless call to dc_get_contact()"); return ptr::null_mut(); } @@ -1157,6 +1230,7 @@ pub unsafe extern "C" fn dc_imex( param2: *mut libc::c_char, ) { if context.is_null() { + eprintln!("ignoring careless call to dc_imex()"); return; } @@ -1171,6 +1245,7 @@ pub unsafe extern "C" fn dc_imex_has_backup( dir: *mut libc::c_char, ) -> *mut libc::c_char { if context.is_null() || dir.is_null() { + eprintln!("ignoring careless call to dc_imex_has_backup()"); return 0; } @@ -1182,6 +1257,7 @@ pub unsafe extern "C" fn dc_imex_has_backup( #[no_mangle] pub unsafe extern "C" fn dc_initiate_key_transfer(context: *mut dc_context_t) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_initiate_key_transfer()"); return 0; } @@ -1200,6 +1276,7 @@ pub unsafe extern "C" fn dc_continue_key_transfer( || msg_id <= constants::DC_MSG_ID_LAST_SPECIAL as u32 || setup_code.is_null() { + eprintln!("ignoring careless call to dc_continue_key_transfer()"); return 0; } @@ -1211,6 +1288,7 @@ pub unsafe extern "C" fn dc_continue_key_transfer( #[no_mangle] pub unsafe extern "C" fn dc_stop_ongoing_process(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_stop_ongoing_process()"); return; } @@ -1225,6 +1303,7 @@ pub unsafe extern "C" fn dc_check_qr( qr: *mut libc::c_char, ) -> *mut dc_lot_t { if context.is_null() || qr.is_null() { + eprintln!("ignoring careless call to dc_check_qr()"); return ptr::null_mut(); } @@ -1240,6 +1319,7 @@ pub unsafe extern "C" fn dc_get_securejoin_qr( chat_id: u32, ) -> *mut libc::c_char { if context.is_null() { + eprintln!("ignoring careless call to dc_get_securejoin_qr()"); return dc_strdup(ptr::null()); } @@ -1254,6 +1334,7 @@ pub unsafe extern "C" fn dc_join_securejoin( qr: *mut libc::c_char, ) -> u32 { if context.is_null() || qr.is_null() { + eprintln!("ignoring careless call to dc_join_securejoin()"); return 0; } @@ -1269,6 +1350,7 @@ pub unsafe extern "C" fn dc_send_locations_to_chat( seconds: libc::c_int, ) { if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 || seconds < 0 { + eprintln!("ignoring careless call to dc_send_locations_to_chat()"); return; } @@ -1283,6 +1365,7 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat( chat_id: u32, ) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_is_sending_locations_to_chat()"); return 0; } @@ -1299,6 +1382,7 @@ pub unsafe extern "C" fn dc_set_location( accuracy: libc::c_double, ) -> libc::c_int { if context.is_null() { + eprintln!("ignoring careless call to dc_set_location()"); return 0; } @@ -1316,6 +1400,7 @@ pub unsafe extern "C" fn dc_get_locations( timestamp_end: i64, ) -> *mut dc_array::dc_array_t { if context.is_null() { + eprintln!("ignoring careless call to dc_get_locations()"); return ptr::null_mut(); } @@ -1334,6 +1419,7 @@ pub unsafe extern "C" fn dc_get_locations( #[no_mangle] pub unsafe extern "C" fn dc_delete_all_locations(context: *mut dc_context_t) { if context.is_null() { + eprintln!("ignoring careless call to dc_delete_all_locations()"); return; } @@ -1350,6 +1436,7 @@ pub type dc_array_t = dc_array::dc_array_t; #[no_mangle] pub unsafe extern "C" fn dc_array_unref(a: *mut dc_array::dc_array_t) { if a.is_null() { + eprintln!("ignoring careless call to dc_array_unref()"); return; } @@ -1359,6 +1446,7 @@ pub unsafe extern "C" fn dc_array_unref(a: *mut dc_array::dc_array_t) { #[no_mangle] pub unsafe extern "C" fn dc_array_add_id(array: *mut dc_array_t, item: libc::c_uint) { if array.is_null() { + eprintln!("ignoring careless call to dc_array_add_id()"); return; } @@ -1368,6 +1456,7 @@ pub unsafe extern "C" fn dc_array_add_id(array: *mut dc_array_t, item: libc::c_u #[no_mangle] pub unsafe extern "C" fn dc_array_get_cnt(array: *const dc_array_t) -> libc::size_t { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_cnt()"); return 0; } @@ -1376,6 +1465,7 @@ pub unsafe extern "C" fn dc_array_get_cnt(array: *const dc_array_t) -> libc::siz #[no_mangle] pub unsafe extern "C" fn dc_array_get_id(array: *const dc_array_t, index: libc::size_t) -> u32 { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_id()"); return 0; } @@ -1387,6 +1477,7 @@ pub unsafe extern "C" fn dc_array_get_latitude( index: libc::size_t, ) -> libc::c_double { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_latitude()"); return 0; } @@ -1398,6 +1489,7 @@ pub unsafe extern "C" fn dc_array_get_longitude( index: libc::size_t, ) -> libc::c_double { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_longitude()"); return 0; } @@ -1409,6 +1501,7 @@ pub unsafe extern "C" fn dc_array_get_accuracy( index: libc::size_t, ) -> libc::c_double { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_accuracy()"); return 0; } @@ -1420,6 +1513,7 @@ pub unsafe extern "C" fn dc_array_get_timestamp( index: libc::size_t, ) -> i64 { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_timestamp()"); return 0; } @@ -1431,6 +1525,7 @@ pub unsafe extern "C" fn dc_array_get_chat_id( index: libc::size_t, ) -> libc::c_uint { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_chat_id()"); return 0; } @@ -1442,6 +1537,7 @@ pub unsafe extern "C" fn dc_array_get_contact_id( index: libc::size_t, ) -> libc::c_uint { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_contact_id()"); return 0; } @@ -1453,6 +1549,7 @@ pub unsafe extern "C" fn dc_array_get_msg_id( index: libc::size_t, ) -> libc::c_uint { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_msg_id()"); return 0; } @@ -1464,6 +1561,7 @@ pub unsafe extern "C" fn dc_array_get_marker( index: libc::size_t, ) -> *mut libc::c_char { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_marker()"); return 0; } @@ -1481,6 +1579,7 @@ pub unsafe extern "C" fn dc_array_search_id( ret_index: *mut libc::size_t, ) -> libc::c_int { if array.is_null() { + eprintln!("ignoring careless call to dc_array_search_id()"); return 0; } @@ -1497,6 +1596,7 @@ pub unsafe extern "C" fn dc_array_search_id( #[no_mangle] pub unsafe extern "C" fn dc_array_get_raw(array: *const dc_array_t) -> *const u32 { if array.is_null() { + eprintln!("ignoring careless call to dc_array_get_raw()"); return ptr::null_mut(); } @@ -1513,6 +1613,7 @@ pub unsafe fn dc_array_is_independent( index: libc::size_t, ) -> libc::c_int { if array.is_null() { + eprintln!("ignoring careless call to dc_array_is_independent()"); return 0; } @@ -1527,6 +1628,7 @@ pub type dc_chatlist_t<'a> = chatlist::Chatlist<'a>; #[no_mangle] pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist_t) { if chatlist.is_null() { + eprintln!("ignoring careless call to dc_chatlist_unref()"); return; } @@ -1536,6 +1638,7 @@ pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist_t) { #[no_mangle] pub unsafe extern "C" fn dc_chatlist_get_cnt(chatlist: *mut dc_chatlist_t) -> libc::size_t { if chatlist.is_null() { + eprintln!("ignoring careless call to dc_chatlist_get_cnt()"); return 0; } @@ -1549,6 +1652,7 @@ pub unsafe extern "C" fn dc_chatlist_get_chat_id( index: libc::size_t, ) -> u32 { if chatlist.is_null() { + eprintln!("ignoring careless call to dc_chatlist_get_chat_id()"); return 0; } @@ -1562,6 +1666,7 @@ pub unsafe extern "C" fn dc_chatlist_get_msg_id( index: libc::size_t, ) -> u32 { if chatlist.is_null() { + eprintln!("ignoring careless call to dc_chatlist_get_msg_id()"); return 0; } @@ -1576,6 +1681,7 @@ pub unsafe extern "C" fn dc_chatlist_get_summary<'a>( chat: *mut dc_chat_t<'a>, ) -> *mut dc_lot_t { if chatlist.is_null() { + eprintln!("ignoring careless call to dc_chatlist_get_summary()"); return ptr::null_mut(); } @@ -1591,6 +1697,7 @@ pub unsafe extern "C" fn dc_chatlist_get_context( chatlist: *mut dc_chatlist_t, ) -> *const dc_context_t { if chatlist.is_null() { + eprintln!("ignoring careless call to dc_chatlist_get_context()"); return ptr::null_mut(); } @@ -1607,6 +1714,7 @@ pub type dc_chat_t<'a> = chat::Chat<'a>; #[no_mangle] pub unsafe extern "C" fn dc_chat_unref(chat: *mut dc_chat_t) { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_unref()"); return; } @@ -1616,6 +1724,7 @@ pub unsafe extern "C" fn dc_chat_unref(chat: *mut dc_chat_t) { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_id(chat: *mut dc_chat_t) -> u32 { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_id()"); return 0; } @@ -1627,6 +1736,7 @@ pub unsafe extern "C" fn dc_chat_get_id(chat: *mut dc_chat_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_type(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_type()"); return 0; } @@ -1638,6 +1748,7 @@ pub unsafe extern "C" fn dc_chat_get_type(chat: *mut dc_chat_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_name(chat: *mut dc_chat_t) -> *mut libc::c_char { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_name()"); return dc_strdup(ptr::null()); } @@ -1649,6 +1760,7 @@ pub unsafe extern "C" fn dc_chat_get_name(chat: *mut dc_chat_t) -> *mut libc::c_ #[no_mangle] pub unsafe extern "C" fn dc_chat_get_subtitle(chat: *mut dc_chat_t) -> *mut libc::c_char { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_subtitle()"); return dc_strdup(ptr::null()); } @@ -1660,6 +1772,7 @@ pub unsafe extern "C" fn dc_chat_get_subtitle(chat: *mut dc_chat_t) -> *mut libc #[no_mangle] pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut libc::c_char { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_profile_image()"); return ptr::null_mut(); // NULL explicitly defined as "no image" } @@ -1674,6 +1787,7 @@ pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut #[no_mangle] pub unsafe extern "C" fn dc_chat_get_color(chat: *mut dc_chat_t) -> u32 { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_color()"); return 0; } @@ -1685,6 +1799,7 @@ pub unsafe extern "C" fn dc_chat_get_color(chat: *mut dc_chat_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_chat_get_archived(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_get_archived()"); return 0; } @@ -1696,6 +1811,7 @@ pub unsafe extern "C" fn dc_chat_get_archived(chat: *mut dc_chat_t) -> libc::c_i #[no_mangle] pub unsafe extern "C" fn dc_chat_is_unpromoted(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_is_unpromoted()"); return 0; } @@ -1707,6 +1823,7 @@ pub unsafe extern "C" fn dc_chat_is_unpromoted(chat: *mut dc_chat_t) -> libc::c_ #[no_mangle] pub unsafe extern "C" fn dc_chat_is_self_talk(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_is_self_talk()"); return 0; } @@ -1718,6 +1835,7 @@ pub unsafe extern "C" fn dc_chat_is_self_talk(chat: *mut dc_chat_t) -> libc::c_i #[no_mangle] pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_is_verified()"); return 0; } @@ -1729,6 +1847,7 @@ pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_in #[no_mangle] pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_is_sending_locations()"); return 0; } @@ -1748,6 +1867,7 @@ pub unsafe extern "C" fn dc_msg_new<'a>( viewtype: libc::c_int, ) -> *mut dc_msg_t<'a> { if context.is_null() { + eprintln!("ignoring careless call to dc_msg_new()"); return ptr::null_mut(); } @@ -1760,6 +1880,7 @@ pub unsafe extern "C" fn dc_msg_new<'a>( #[no_mangle] pub unsafe extern "C" fn dc_msg_unref(msg: *mut dc_msg_t) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_unref()"); return; } @@ -1769,6 +1890,7 @@ pub unsafe extern "C" fn dc_msg_unref(msg: *mut dc_msg_t) { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg_t) -> u32 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_id()"); return 0; } @@ -1779,6 +1901,7 @@ pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg_t) -> u32 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_from_id()"); return 0; } @@ -1789,6 +1912,7 @@ pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg_t) -> u32 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_chat_id()"); return 0; } @@ -1799,6 +1923,7 @@ pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_viewtype()"); return 0; } @@ -1811,6 +1936,7 @@ pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_get_state(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_state()"); return 0; } @@ -1821,6 +1947,7 @@ pub unsafe extern "C" fn dc_msg_get_state(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_timestamp(msg: *mut dc_msg_t) -> i64 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_received_timestamp()"); return 0; } @@ -1831,6 +1958,7 @@ pub unsafe extern "C" fn dc_msg_get_timestamp(msg: *mut dc_msg_t) -> i64 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_received_timestamp(msg: *mut dc_msg_t) -> i64 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_received_timestamp()"); return 0; } @@ -1841,6 +1969,7 @@ pub unsafe extern "C" fn dc_msg_get_received_timestamp(msg: *mut dc_msg_t) -> i6 #[no_mangle] pub unsafe extern "C" fn dc_msg_get_sort_timestamp(msg: *mut dc_msg_t) -> i64 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_sort_timestamp()"); return 0; } @@ -1851,6 +1980,7 @@ pub unsafe extern "C" fn dc_msg_get_sort_timestamp(msg: *mut dc_msg_t) -> i64 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg_t) -> *mut libc::c_char { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_text()"); return dc_strdup(ptr::null()); } @@ -1861,6 +1991,7 @@ pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg_t) -> *mut libc::c_cha #[no_mangle] pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_char { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_file()"); return dc_strdup(ptr::null()); } @@ -1871,6 +2002,7 @@ pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_cha #[no_mangle] pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c_char { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_filename()"); return dc_strdup(ptr::null()); } @@ -1881,6 +2013,7 @@ pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c #[no_mangle] pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c_char { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_filemime()"); return dc_strdup(ptr::null()); } @@ -1891,6 +2024,7 @@ pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c #[no_mangle] pub unsafe extern "C" fn dc_msg_get_filebytes(msg: *mut dc_msg_t) -> u64 { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_filebytes()"); return 0; } @@ -1901,6 +2035,7 @@ pub unsafe extern "C" fn dc_msg_get_filebytes(msg: *mut dc_msg_t) -> u64 { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_width(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_width()"); return 0; } @@ -1911,6 +2046,7 @@ pub unsafe extern "C" fn dc_msg_get_width(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_height(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_height()"); return 0; } @@ -1921,6 +2057,7 @@ pub unsafe extern "C" fn dc_msg_get_height(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_get_duration(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_duration()"); return 0; } @@ -1931,6 +2068,7 @@ pub unsafe extern "C" fn dc_msg_get_duration(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_get_showpadlock(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_showpadlock()"); return 0; } @@ -1944,6 +2082,7 @@ pub unsafe extern "C" fn dc_msg_get_summary<'a>( chat: *mut dc_chat_t<'a>, ) -> *mut dc_lot_t { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_summary()"); return ptr::null_mut(); } let chat = if chat.is_null() { None } else { Some(&*chat) }; @@ -1960,6 +2099,7 @@ pub unsafe extern "C" fn dc_msg_get_summarytext( approx_characters: libc::c_int, ) -> *mut libc::c_char { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_summarytext()"); return dc_strdup(ptr::null()); } @@ -1970,6 +2110,7 @@ pub unsafe extern "C" fn dc_msg_get_summarytext( #[no_mangle] pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_has_deviating_timestamp()"); return 0; } @@ -1980,6 +2121,7 @@ pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg_t) -> l #[no_mangle] pub unsafe extern "C" fn dc_msg_has_location(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_has_location()"); return 0; } @@ -1990,6 +2132,7 @@ pub unsafe extern "C" fn dc_msg_has_location(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_sent()"); return 0; } @@ -2000,6 +2143,7 @@ pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_is_starred(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_starred()"); return 0; } @@ -2010,6 +2154,7 @@ pub unsafe extern "C" fn dc_msg_is_starred(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_forwarded()"); return 0; } @@ -2020,6 +2165,7 @@ pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_info()"); return 0; } @@ -2030,6 +2176,7 @@ pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_increation()"); return 0; } @@ -2040,6 +2187,7 @@ pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int #[no_mangle] pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_setupmessage()"); return 0; } @@ -2050,6 +2198,7 @@ pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_i #[no_mangle] pub unsafe extern "C" fn dc_msg_get_setupcodebegin(msg: *mut dc_msg_t) -> *mut libc::c_char { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_setupcodebegin()"); return dc_strdup(ptr::null()); } @@ -2060,6 +2209,7 @@ pub unsafe extern "C" fn dc_msg_get_setupcodebegin(msg: *mut dc_msg_t) -> *mut l #[no_mangle] pub unsafe extern "C" fn dc_msg_set_text(msg: *mut dc_msg_t, text: *mut libc::c_char) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_set_text()"); return; } @@ -2075,6 +2225,7 @@ pub unsafe extern "C" fn dc_msg_set_file( filemime: *mut libc::c_char, ) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_set_file()"); return; } @@ -2089,6 +2240,7 @@ pub unsafe extern "C" fn dc_msg_set_dimension( height: libc::c_int, ) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_set_dimension()"); return; } @@ -2099,6 +2251,7 @@ pub unsafe extern "C" fn dc_msg_set_dimension( #[no_mangle] pub unsafe extern "C" fn dc_msg_set_duration(msg: *mut dc_msg_t, duration: libc::c_int) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_set_duration()"); return; } @@ -2113,6 +2266,7 @@ pub unsafe extern "C" fn dc_msg_set_location( longitude: libc::c_double, ) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_set_location()"); return; } @@ -2128,6 +2282,7 @@ pub unsafe extern "C" fn dc_msg_latefiling_mediasize( duration: libc::c_int, ) { if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_latefiling_mediasize()"); return; } @@ -2143,6 +2298,7 @@ pub type dc_contact_t<'a> = contact::Contact<'a>; #[no_mangle] pub unsafe extern "C" fn dc_contact_unref(contact: *mut dc_contact_t) { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_unref()"); return; } @@ -2152,6 +2308,7 @@ pub unsafe extern "C" fn dc_contact_unref(contact: *mut dc_contact_t) { #[no_mangle] pub unsafe extern "C" fn dc_contact_get_id(contact: *mut dc_contact_t) -> u32 { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_id()"); return 0; } @@ -2163,6 +2320,7 @@ pub unsafe extern "C" fn dc_contact_get_id(contact: *mut dc_contact_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_contact_get_addr(contact: *mut dc_contact_t) -> *mut libc::c_char { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_addr()"); return dc_strdup(ptr::null()); } @@ -2174,6 +2332,7 @@ pub unsafe extern "C" fn dc_contact_get_addr(contact: *mut dc_contact_t) -> *mut #[no_mangle] pub unsafe extern "C" fn dc_contact_get_name(contact: *mut dc_contact_t) -> *mut libc::c_char { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_name()"); return dc_strdup(ptr::null()); } @@ -2187,6 +2346,7 @@ pub unsafe extern "C" fn dc_contact_get_display_name( contact: *mut dc_contact_t, ) -> *mut libc::c_char { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_display_name()"); return dc_strdup(ptr::null()); } @@ -2200,6 +2360,7 @@ pub unsafe extern "C" fn dc_contact_get_name_n_addr( contact: *mut dc_contact_t, ) -> *mut libc::c_char { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_name_n_addr()"); return dc_strdup(ptr::null()); } @@ -2213,6 +2374,7 @@ pub unsafe extern "C" fn dc_contact_get_first_name( contact: *mut dc_contact_t, ) -> *mut libc::c_char { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_first_name()"); return dc_strdup(ptr::null()); } @@ -2226,6 +2388,7 @@ pub unsafe extern "C" fn dc_contact_get_profile_image( contact: *mut dc_contact_t, ) -> *mut libc::c_char { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_profile_image()"); return ptr::null_mut(); // NULL explicitly defined as "no profile image" } @@ -2240,6 +2403,7 @@ pub unsafe extern "C" fn dc_contact_get_profile_image( #[no_mangle] pub unsafe extern "C" fn dc_contact_get_color(contact: *mut dc_contact_t) -> u32 { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_color()"); return 0; } @@ -2251,6 +2415,7 @@ pub unsafe extern "C" fn dc_contact_get_color(contact: *mut dc_contact_t) -> u32 #[no_mangle] pub unsafe extern "C" fn dc_contact_is_blocked(contact: *mut dc_contact_t) -> libc::c_int { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_is_blocked()"); return 0; } @@ -2262,6 +2427,7 @@ pub unsafe extern "C" fn dc_contact_is_blocked(contact: *mut dc_contact_t) -> li #[no_mangle] pub unsafe extern "C" fn dc_contact_is_verified(contact: *mut dc_contact_t) -> libc::c_int { if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_is_verified()"); return 0; } @@ -2278,6 +2444,7 @@ pub type dc_lot_t = lot::Lot; #[no_mangle] pub unsafe extern "C" fn dc_lot_unref(lot: *mut dc_lot_t) { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_unref()"); return; } @@ -2287,6 +2454,7 @@ pub unsafe extern "C" fn dc_lot_unref(lot: *mut dc_lot_t) { #[no_mangle] pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_char { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_get_text1()"); return ptr::mut_null(); // NULL explicitly defined as "there is no such text" } @@ -2297,6 +2465,7 @@ pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_ch #[no_mangle] pub unsafe extern "C" fn dc_lot_get_text2(lot: *mut dc_lot_t) -> *mut libc::c_char { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_get_text2()"); return ptr::mut_null(); // NULL explicitly defined as "there is no such text" } @@ -2307,6 +2476,7 @@ pub unsafe extern "C" fn dc_lot_get_text2(lot: *mut dc_lot_t) -> *mut libc::c_ch #[no_mangle] pub unsafe extern "C" fn dc_lot_get_text1_meaning(lot: *mut dc_lot_t) -> libc::c_int { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_get_text1_meaning()"); return 0; } @@ -2317,6 +2487,7 @@ pub unsafe extern "C" fn dc_lot_get_text1_meaning(lot: *mut dc_lot_t) -> libc::c #[no_mangle] pub unsafe extern "C" fn dc_lot_get_state(lot: *mut dc_lot_t) -> libc::c_int { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_get_state()"); return 0; } @@ -2327,6 +2498,7 @@ pub unsafe extern "C" fn dc_lot_get_state(lot: *mut dc_lot_t) -> libc::c_int { #[no_mangle] pub unsafe extern "C" fn dc_lot_get_id(lot: *mut dc_lot_t) -> u32 { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_get_id()"); return 0; } @@ -2337,6 +2509,7 @@ pub unsafe extern "C" fn dc_lot_get_id(lot: *mut dc_lot_t) -> u32 { #[no_mangle] pub unsafe extern "C" fn dc_lot_get_timestamp(lot: *mut dc_lot_t) -> i64 { if lot.is_null() { + eprintln!("ignoring careless call to dc_lot_get_timestamp()"); return 0; } From 8902d0843b7657f3e0af296e4d8f6b8bbdfd4ff5 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 28 Aug 2019 18:32:34 +0200 Subject: [PATCH 3/3] fix some return values --- deltachat-ffi/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index f5d09a2dd..fa768badd 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1246,7 +1246,7 @@ pub unsafe extern "C" fn dc_imex_has_backup( ) -> *mut libc::c_char { if context.is_null() || dir.is_null() { eprintln!("ignoring careless call to dc_imex_has_backup()"); - return 0; + return ptr::null_mut(); // NULL explicitly defined as "has no backup" } let context = &*context; @@ -1258,7 +1258,7 @@ pub unsafe extern "C" fn dc_imex_has_backup( pub unsafe extern "C" fn dc_initiate_key_transfer(context: *mut dc_context_t) -> *mut libc::c_char { if context.is_null() { eprintln!("ignoring careless call to dc_initiate_key_transfer()"); - return 0; + return ptr::null_mut(); // NULL explicitly defined as "error" } let context = &*context; @@ -1478,7 +1478,7 @@ pub unsafe extern "C" fn dc_array_get_latitude( ) -> libc::c_double { if array.is_null() { eprintln!("ignoring careless call to dc_array_get_latitude()"); - return 0; + return 0.0; } (*array).get_location(index).latitude @@ -1490,7 +1490,7 @@ pub unsafe extern "C" fn dc_array_get_longitude( ) -> libc::c_double { if array.is_null() { eprintln!("ignoring careless call to dc_array_get_longitude()"); - return 0; + return 0.0; } (*array).get_location(index).longitude @@ -1502,7 +1502,7 @@ pub unsafe extern "C" fn dc_array_get_accuracy( ) -> libc::c_double { if array.is_null() { eprintln!("ignoring careless call to dc_array_get_accuracy()"); - return 0; + return 0.0; } (*array).get_location(index).accuracy @@ -1562,7 +1562,7 @@ pub unsafe extern "C" fn dc_array_get_marker( ) -> *mut libc::c_char { if array.is_null() { eprintln!("ignoring careless call to dc_array_get_marker()"); - return 0; + return std::ptr::null_mut(); // NULL explicitly defined as "no markers" } if let Some(s) = &(*array).get_location(index).marker { @@ -2455,7 +2455,7 @@ pub unsafe extern "C" fn dc_lot_unref(lot: *mut dc_lot_t) { pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_char { if lot.is_null() { eprintln!("ignoring careless call to dc_lot_get_text1()"); - return ptr::mut_null(); // NULL explicitly defined as "there is no such text" + return ptr::null_mut(); // NULL explicitly defined as "there is no such text" } let lot = &*lot; @@ -2466,7 +2466,7 @@ pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_ch pub unsafe extern "C" fn dc_lot_get_text2(lot: *mut dc_lot_t) -> *mut libc::c_char { if lot.is_null() { eprintln!("ignoring careless call to dc_lot_get_text2()"); - return ptr::mut_null(); // NULL explicitly defined as "there is no such text" + return ptr::null_mut(); // NULL explicitly defined as "there is no such text" } let lot = &*lot;