From d5dfd55a2963018c969e5a0c4a8da194d4b34f75 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 21 Jan 2008 15:04:57 +0000 Subject: [PATCH] * adding some precondition checks, hopefully adding some stability. with permission from senor Villar pmo-trunk-r4070 --- src/maemo/modest-main-window.c | 2 ++ src/maemo/modest-platform.c | 7 +++++++ src/modest-mail-operation.c | 5 +++++ src/modest-tny-account-store.c | 17 ++++++++++++++--- src/modest-ui-actions.c | 2 +- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index a39c31a..3d1b31b 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -2694,6 +2694,8 @@ modest_main_window_screen_is_on (ModestMainWindow *self) { ModestMainWindowPrivate *priv = NULL; + g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(self), FALSE); + priv = MODEST_MAIN_WINDOW_GET_PRIVATE (self); return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE; diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 3ff9177..f34538c 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -1342,6 +1342,13 @@ modest_platform_on_new_headers_received (TnyList *header_list, { gboolean play_sound; + g_return_if_fail (TNY_IS_LIST(header_list)); + + if (tny_list_get_length(header_list) == 0) { + g_warning ("%s: header list is empty", __FUNCTION__); + return; + } + /* Check whether or not we should play a sound */ play_sound = modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index f425061..522997a 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -706,6 +706,11 @@ send_mail_error_happened_handler (TnySendQueue *queue, TnyHeader *header, TnyMsg SendMsgInfo *info = (SendMsgInfo *) userdata; TnyHeader *hdr1, *hdr2; const char *msgid1, *msgid2; + + if (!TNY_IS_MSG(msg)) { + g_warning ("%s: did not receive a valid msg", __FUNCTION__); + return; + } hdr1 = tny_msg_get_header(msg); hdr2 = tny_msg_get_header(info->msg); diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 2bdb4eb..2dd83d0 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -30,10 +30,10 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -1199,14 +1199,25 @@ get_tny_account_by (TnyList *accounts, gboolean found = FALSE; TnyAccount *retval = NULL; - g_return_val_if_fail (accounts && TNY_IS_LIST(accounts), NULL); + g_return_val_if_fail (TNY_IS_LIST(accounts), NULL); + if (tny_list_get_length(accounts) == 0) { + g_warning ("%s: account list is empty", __FUNCTION__); + return NULL; + } + iter = tny_list_create_iterator (accounts); while (!tny_iterator_is_done (iter) && !found) { TnyAccount *tmp_account = NULL; const gchar *val = NULL; tmp_account = TNY_ACCOUNT (tny_iterator_get_current (iter)); + if (!TNY_IS_ACCOUNT(tmp_account)) { + g_warning ("%s: not a valid account", __FUNCTION__); + tmp_account = NULL; + break; + } + switch (type) { case MODEST_TNY_ACCOUNT_STORE_QUERY_ID: val = tny_account_get_id (tmp_account); @@ -1221,7 +1232,7 @@ get_tny_account_by (TnyList *accounts, retval = g_object_ref (tmp_account); found = TRUE; } else { - if (strcmp (val, str) == 0) { + if (val && str && strcmp (val, str) == 0) { retval = g_object_ref (tmp_account); found = TRUE; } diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index fd84c02..d495f70 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1674,7 +1674,7 @@ new_messages_arrived (ModestMailOperation *self, send&receive was invoked by the user then do not show any visual notification, only play a sound and activate the LED (for the Maemo version) */ - if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0)) + if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0) modest_platform_on_new_headers_received (new_headers, show_visual_notifications); -- 1.7.9.5