[Patch] fix some issues detected by cppcheck

Albrecht Dreß <[email protected]>
Newsgroups gmane.comp.gnome.apps.balsa
Message-ID <[email protected]>
Hi all,

the latest cppcheck version 1.85 [1] detected a bunch of issues in the git master code which are fixed by the attached (trivial) patch.  Note that even with this patch, cppcheck nags about some issues in libbalsa/imap/imap-commands.c which I believe are false positives.  Furthermore, there is some apparently “dead” code in src/mailbox-conf.c which I still have to investigate.

Cheers,
Albrecht.

[1] <http://cppcheck.net/>

---
Patch details:
- libbalsa/imap/auth-gssapi.c: fix (unlikely) uninitialised use of rc
- libbalsa/imap/imap-auth.c: do not dereference NULL pointer if an error occurred
- libbalsa/libbalsa.c: fix signed/unsigned mismatch, and use g_debug instead of printf
- libbalsa/mailbox_imap.c: fix signed/unsigned mismatch
- libinit_balsa/assistant_page_directory.c: fix different parameters names in function prototype and implementation
- src/balsa-message.c, src/save-restore.c: do no dereference pointer before checking it it is not NULL
- src/sendmsg-window.c: fix false-positive about NULL pointer dereference
- src/store-address.c: fix false-positive by splitting an over-complex construct

_______________________________________________
balsa-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/balsa-list
fix_cppcheck_nagging.diff (text/x-patch, 4.8 KB)
diff --git a/libbalsa/imap/auth-gssapi.c b/libbalsa/imap/auth-gssapi.c
index 14a2de569..e70d560a2 100644
--- a/libbalsa/imap/auth-gssapi.c
+++ b/libbalsa/imap/auth-gssapi.c
@@ -148,6 +148,8 @@ imap_auth_gssapi(ImapMboxHandle* handle)
     			(void) net_client_write_line(NET_CLIENT(handle->sio), "*", NULL);
     		}
     		rc = imap_cmd_process_untagged(handle, cmdno);
+    	} else {
+    		rc = IMR_BAD;
     	}
 
 		net_client_gss_ctx_free(gss_ctx);
diff --git a/libbalsa/imap/imap-auth.c b/libbalsa/imap/imap-auth.c
index febc0859a..91335bd50 100644
--- a/libbalsa/imap/imap-auth.c
+++ b/libbalsa/imap/imap-auth.c
@@ -182,9 +182,11 @@ getmsg_plain(ImapMboxHandle *h, char **retmsg, int *retmsglen)
 		*retmsglen = strlen(*retmsg);
 		result = TRUE;
 	}
-	net_client_free_authstr(auth_data[0]);
-	net_client_free_authstr(auth_data[1]);
-	g_free(auth_data);
+	if (auth_data != NULL) {
+		net_client_free_authstr(auth_data[0]);
+		net_client_free_authstr(auth_data[1]);
+		g_free(auth_data);
+	}
 	return result;
 }
 
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index 38096642c..090a0fcff 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -616,7 +616,7 @@ ask_cert_real(void *data)
      * not really necessary but helps with debugging. */
    while(gtk_events_pending()) 
         gtk_main_iteration_do(FALSE);
-    printf("%s returns %d\n", __FUNCTION__, i);
+    g_debug("%s returns %u", __func__, i);
     return i;
 }
 
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 70a7650a3..128ebd357 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -2313,9 +2313,9 @@ static gboolean
 is_child_of(LibBalsaMessageBody *body, LibBalsaMessageBody *child,
             GString *s, gboolean modify)
 {
-    int i = 1;
+    guint i;
     gboolean do_mod;
-    for(i=1; body; body = body->next) {
+    for(i=1U; body; body = body->next) {
         if(body==child) {
             g_string_printf(s, "%u", i);
             return TRUE;
diff --git a/libinit_balsa/assistant_page_directory.c b/libinit_balsa/assistant_page_directory.c
index 279fdfc77..7499884ce 100644
--- a/libinit_balsa/assistant_page_directory.c
+++ b/libinit_balsa/assistant_page_directory.c
@@ -389,7 +389,7 @@ balsa_druid_page_directory_back(GtkAssistant *druid, GtkWidget *page,
 }
 
 static void
-balsa_druid_page_directory_next(GtkAssistant * page, GtkWidget * druid,
+balsa_druid_page_directory_next(GtkAssistant *druid, GtkWidget *page,
                                 BalsaDruidPageDirectory * dir)
 {
     dir->paths_locked = TRUE;
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 98d10468e..1ad4ec1dc 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -1136,10 +1136,11 @@ balsa_message_set(BalsaMessage * bm, LibBalsaMailbox * mailbox, guint msgno)
     gboolean is_new;
     GtkTreeIter iter;
     BalsaPartInfo *info;
-    gboolean has_focus = bm->focus_state != BALSA_MESSAGE_FOCUS_STATE_NO;
+    gboolean has_focus;
     LibBalsaMessage *message;
 
     g_return_val_if_fail(bm != NULL, FALSE);
+    has_focus = bm->focus_state != BALSA_MESSAGE_FOCUS_STATE_NO;
 
     bm_disable_find_entry(bm);
     balsa_message_clear_tree(bm);
diff --git a/src/save-restore.c b/src/save-restore.c
index 0615326f6..3d306be24 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -449,9 +449,10 @@ static gint
 config_mailbox_init(const gchar * prefix)
 {
     LibBalsaMailbox *mailbox;
-    const gchar *key = prefix + strlen(MAILBOX_SECTION_PREFIX);
+    const gchar *key;
 
     g_return_val_if_fail(prefix != NULL, FALSE);
+    key = prefix + strlen(MAILBOX_SECTION_PREFIX);
 
     mailbox = libbalsa_mailbox_new_from_config(prefix, is_special_name(key));
     if (mailbox == NULL)
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 7244a76c2..5e39b2715 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -6239,8 +6239,7 @@ sendmsg_window_new_from_list(LibBalsaMailbox * mailbox,
         break;
     default:
         g_assert_not_reached(); /* since it hardly makes sense... */
-        bsmsg = NULL; /** silence invalid warnings */
-
+        return NULL; /* silence invalid warnings */
     }
     g_object_unref(message);
 
diff --git a/src/store-address.c b/src/store-address.c
index 5efd9aebb..0130e5233 100644
--- a/src/store-address.c
+++ b/src/store-address.c
@@ -375,8 +375,11 @@ store_address_add_address(StoreAddressInfo * info,
 
     text = internet_address_to_string(ia, FALSE);
     address = libbalsa_address_new();
-    address->full_name =
-        g_strdup(ia->name ? ia->name : group ? group->name : NULL);
+    if (ia->name != NULL) {
+    	address->full_name = g_strdup(ia->name);
+    } else {
+    	address->full_name = g_strdup((group != NULL) ? group->name : NULL);
+    }
     if (INTERNET_ADDRESS_IS_GROUP(ia)) {
         InternetAddressList *members;
         int j;
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEEcCEPemLFTtyGf4zATKlvDmfn2fgFAlwKuJ4ACgkQTKlvDmfn
2fjYLAgArHdSdm6bmueN8vY1QWjEywH2v5S8d8Y7sAFm/M/H9epSxN4bvVT/Ynz8
3TFo2AtKEvaRIqR8lqBNKH6RApQOgr12uoKjM45nmhA431UxgQOFNWTiZBLHcRy2
xecBy8EZGVFookOd4nkjvRYWvIz2prRhRgmZ/C55QL5K5jtlr0DpiqLY4dNXXf+N
e4gKMEWHL29CSpnAqXw7UTJl/fHNtTYzVgEViDxqSzKlOypSoGMSn+NMVdT+IICm
SYujnurgfF3oJUzMsalaKhfSybjsFUIgljXHhljwQJI4i9WsmVOxjIU1BIw/DeCp
FdOXr357tveu8X9SfavYiDe/0kNmXQ==
=L3cU
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.