[balsa] Use g_strcmp0() for NULL-safe comparisons
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] Use g_strcmp0() for NULL-safe comparisons
- Date: Fri, 1 Jun 2018 02:37:15 +0000 (UTC)
commit 0a846e0560aae3b440f5699f15c2137b3c9dfa07
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Thu May 31 22:19:42 2018 -0400
Use g_strcmp0() for NULL-safe comparisons
* libbalsa/address-book-rubrica.c (extract_net):
* libbalsa/gmime-gpgme-signature.c
(libbalsa_cert_subject_readable):
* libbalsa/html.c (lbh_mouse_target_changed_cb),
(libbalsa_html_search):
* libbalsa/identity.c (libbalsa_identity_combo_box):
* libbalsa/mailbox.c (libbalsa_mailbox_set_identity_name),
(lbm_try_reassemble):
* libbalsa/mailbox_mbox.c (lbm_mbox_message_new):
* libbalsa/smtp-server.c (smtp_server_compare):
* src/ab-main.c (bab_config_init):
* src/balsa-app.c (find_path), (balsa_quote_regex_new):
* src/balsa-icons.c (load_balsa_pixmap):
* src/filter-edit-callbacks.c (change_filter_name):
* src/folder-conf.c (subfolder_conf_clicked_ok),
(folder_conf_imap_sub_node):
* src/mailbox-node.c (remove_special_mailbox_by_url):
* src/pref-manager.c (open_preferences_manager_idle):
* src/save-restore.c (config_address_book_load):
* src/sendmsg-window.c (sw_preferred_charset),
(find_locale_index_by_locale), (has_file_attached):
ChangeLog | 26 ++++++++++++++++++++++++++
libbalsa/address-book-rubrica.c | 6 +++---
libbalsa/gmime-gpgme-signature.c | 4 ++--
libbalsa/html.c | 9 ++++-----
libbalsa/identity.c | 2 +-
libbalsa/mailbox.c | 5 ++---
libbalsa/mailbox_mbox.c | 5 ++---
libbalsa/smtp-server.c | 5 +----
src/ab-main.c | 3 +--
src/balsa-app.c | 12 +++++-------
src/balsa-icons.c | 2 +-
src/filter-edit-callbacks.c | 14 ++++++++------
src/folder-conf.c | 12 ++++++------
src/mailbox-node.c | 10 +++++-----
src/pref-manager.c | 2 +-
src/save-restore.c | 3 +--
src/sendmsg-window.c | 7 +++----
17 files changed, 72 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 33b6c3901..20245c4ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2018-05-31 Peter Bloomfield <pbloomfield bellsouth net>
+
+ Use g_strcmp0() for NULL-safe comparisons
+
+ * libbalsa/address-book-rubrica.c (extract_net):
+ * libbalsa/gmime-gpgme-signature.c
+ (libbalsa_cert_subject_readable):
+ * libbalsa/html.c (lbh_mouse_target_changed_cb),
+ (libbalsa_html_search):
+ * libbalsa/identity.c (libbalsa_identity_combo_box):
+ * libbalsa/mailbox.c (libbalsa_mailbox_set_identity_name),
+ (lbm_try_reassemble):
+ * libbalsa/mailbox_mbox.c (lbm_mbox_message_new):
+ * libbalsa/smtp-server.c (smtp_server_compare):
+ * src/ab-main.c (bab_config_init):
+ * src/balsa-app.c (find_path), (balsa_quote_regex_new):
+ * src/balsa-icons.c (load_balsa_pixmap):
+ * src/filter-edit-callbacks.c (change_filter_name):
+ * src/folder-conf.c (subfolder_conf_clicked_ok),
+ (folder_conf_imap_sub_node):
+ * src/mailbox-node.c (remove_special_mailbox_by_url):
+ * src/pref-manager.c (open_preferences_manager_idle):
+ * src/save-restore.c (config_address_book_load):
+ * src/sendmsg-window.c (sw_preferred_charset),
+ (find_locale_index_by_locale), (has_file_attached):
+
2018-05-31 Peter Bloomfield <pbloomfield bellsouth net>
* src/filter-edit-callbacks.c (fe_new_pressed): Do not leak
diff --git a/libbalsa/address-book-rubrica.c b/libbalsa/address-book-rubrica.c
index 56bea7bb8..6b7b1b267 100644
--- a/libbalsa/address-book-rubrica.c
+++ b/libbalsa/address-book-rubrica.c
@@ -682,9 +682,9 @@ extract_net(xmlNodePtr entry, GList ** mail_addrs)
gchar *mail_addr;
if (!xmlStrcmp(entry->name, CXMLCHARP("Uri"))
- && (uri_type = xml_node_get_attr(entry, CXMLCHARP("type")))
- && !strcmp(uri_type, "email")
- && (mail_addr = xml_node_get_text(entry)))
+ && g_strcmp0(uri_type = xml_node_get_attr(entry, CXMLCHARP("type")),
+ "email") == 0
+ && (mail_addr = xml_node_get_text(entry) != NULL))
*mail_addrs = g_list_prepend(*mail_addrs, mail_addr);
g_free(uri_type);
diff --git a/libbalsa/gmime-gpgme-signature.c b/libbalsa/gmime-gpgme-signature.c
index 7d86530e4..cab762d3d 100644
--- a/libbalsa/gmime-gpgme-signature.c
+++ b/libbalsa/gmime-gpgme-signature.c
@@ -268,9 +268,9 @@ libbalsa_cert_subject_readable(const gchar *subject)
if (equals) {
*equals++ = '\0';
for (ldap_elem = ldap_id_list;
- ldap_elem->ldap_id && strcmp(ldap_elem->ldap_id, elements[n]);
+ g_strcmp0(ldap_elem->ldap_id, elements[n]) != 0;
ldap_elem++);
- if (ldap_elem->ldap_id)
+ if (ldap_elem->ldap_id != NULL)
result = g_string_append(result, ldap_elem->readable);
else
result = g_string_append(result, elements[n]);
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 19a30c0ec..17f62789e 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -236,18 +236,17 @@ lbh_mouse_target_changed_cb(WebKitWebView * web_view,
uri = webkit_hit_test_result_get_link_uri(hit_test_result);
- if ((!uri && !info->uri)
- || (uri && info->uri && !strcmp(uri, info->uri)))
+ if (g_strcmp0(uri, info->uri) == 0)
/* No change */
return;
- if (info->uri) {
+ if (info->uri != NULL) {
g_free(info->uri);
info->uri = NULL;
(*info->hover_cb) (NULL);
}
- if (uri) {
+ if (uri != NULL) {
info->uri = g_strdup(uri);
(*info->hover_cb) (uri);
}
@@ -890,7 +889,7 @@ libbalsa_html_search(GtkWidget * widget,
info = g_object_get_data(G_OBJECT(web_view), LIBBALSA_HTML_INFO);
controller = webkit_web_view_get_find_controller(web_view);
- if (!info->search_text || strcmp(text, info->search_text)) {
+ if (g_strcmp0(text, info->search_text) != 0) {
lbh_search_init(info, controller, text, find_forward, wrap,
search_cb, cb_data);
} else {
diff --git a/libbalsa/identity.c b/libbalsa/identity.c
index f8783d792..7c902d8af 100644
--- a/libbalsa/identity.c
+++ b/libbalsa/identity.c
@@ -2288,7 +2288,7 @@ libbalsa_identity_combo_box(GList * identities,
g_free(from);
g_free(name);
- if (active_name != NULL && strcmp(active_name, ident->identity_name) == 0)
+ if (g_strcmp0(active_name, ident->identity_name) == 0)
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_box), &iter);
}
g_object_unref(store);
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 5a717960f..59bf9a47e 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -2351,7 +2351,7 @@ libbalsa_mailbox_set_identity_name(LibBalsaMailbox * mailbox,
{
LibBalsaMailboxView *view = lbm_get_view(mailbox);
- if (!view->identity_name || strcmp(view->identity_name, identity_name)) {
+ if (g_strcmp0(view->identity_name, identity_name) != 0) {
g_free(view->identity_name);
view->identity_name = g_strdup(identity_name);
if (mailbox)
@@ -4008,8 +4008,7 @@ lbm_try_reassemble(LibBalsaMailbox * mailbox, const gchar * id)
g_mime_multipart_foreach((GMimeMultipart *)
mime_message->mime_part,
lbm_try_reassemble_func, &partial);
- if (partial
- && strcmp(g_mime_message_partial_get_id(partial), id) == 0) {
+ if (g_strcmp0(g_mime_message_partial_get_id(partial), id) == 0) {
g_ptr_array_add(partials, partial);
if (g_mime_message_partial_get_total(partial) > 0)
total = g_mime_message_partial_get_total(partial);
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index ff5ecbb6c..0b6cb43ff 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -1801,9 +1801,8 @@ lbm_mbox_message_new(GMimeMessage * mime_message,
LibBalsaMessageFlag flags = 0;
#if defined(THIS_HAS_BEEN_TESTED)
- if (mime_message->subject &&
- !strcmp(mime_message->subject,
- "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")) {
+ if (!g_strcmp0(mime_message->subject,
+ "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")) {
return NULL;
}
#endif
diff --git a/libbalsa/smtp-server.c b/libbalsa/smtp-server.c
index 3157ca2db..d74336384 100644
--- a/libbalsa/smtp-server.c
+++ b/libbalsa/smtp-server.c
@@ -191,10 +191,7 @@ smtp_server_compare(gconstpointer a, gconstpointer b)
const LibBalsaSmtpServer *smtp_server_a = a;
const LibBalsaSmtpServer *smtp_server_b = b;
- if (smtp_server_a->name && smtp_server_b->name)
- return strcmp(smtp_server_a->name, smtp_server_b->name);
-
- return smtp_server_a->name - smtp_server_b->name;
+ return g_strcmp0(smtp_server_a->name, smtp_server_b->name);
}
void
diff --git a/src/ab-main.c b/src/ab-main.c
index 5401e451a..5740b1817 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -92,8 +92,7 @@ bab_config_init(const gchar * group, const gchar * value, gpointer data)
contacts_app.address_book_list =
g_list_append(contacts_app.address_book_list, address_book);
- if (contacts_app.default_address_book_prefix
- && strcmp(group,
+ if (g_strcmp0(group,
contacts_app.default_address_book_prefix) == 0)
contacts_app.default_address_book = address_book;
}
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 8e9f9c8e9..3d51715d4 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -611,7 +611,7 @@ find_path(GtkTreeModel * model, GtkTreePath * path, GtkTreeIter * iter,
gtk_tree_model_get(model, iter, 0, &mbnode, -1);
if (mbnode->server == bf->server &&
- mbnode->dir && !strcmp(mbnode->dir, bf->data)) {
+ g_strcmp0(mbnode->dir, bf->data) == 0) {
bf->mbnode = mbnode;
return TRUE;
}
@@ -863,14 +863,12 @@ balsa_quote_regex_new(void)
static GRegex *regex = NULL;
static gchar *string = NULL;
- if (string && strcmp(string, balsa_app.quote_regex) != 0) {
- g_free(string);
- string = NULL;
- g_regex_unref(regex);
- regex = NULL;
+ if (g_strcmp0(string, balsa_app.quote_regex) != 0) {
+ g_clear_pointer(&string, g_free);
+ g_clear_pointer(®ex, g_regex_unref);
}
- if (!regex) {
+ if (regex == NULL) {
GError *err = NULL;
regex = g_regex_new(balsa_app.quote_regex, 0, 0, &err);
diff --git a/src/balsa-icons.c b/src/balsa-icons.c
index da679e89b..71e4987a1 100644
--- a/src/balsa-icons.c
+++ b/src/balsa-icons.c
@@ -76,7 +76,7 @@ load_balsa_pixmap(GtkIconTheme *icon_theme, const balsa_pixmap_t *bpixmap)
* alternative name if not */
if (!gtk_icon_theme_has_icon(icon_theme, bpixmap->stock_id)) {
pixmap_fallback_t *fb = fallback_id;
- while (fb->def_id && strcmp(fb->def_id, bpixmap->stock_id))
+ while (g_strcmp0(fb->def_id, bpixmap->stock_id) != 0)
fb++;
if (fb->def_id) {
use_id = fb->fb_id;
diff --git a/src/filter-edit-callbacks.c b/src/filter-edit-callbacks.c
index 924aa6fbf..ff41d95b6 100644
--- a/src/filter-edit-callbacks.c
+++ b/src/filter-edit-callbacks.c
@@ -1645,7 +1645,7 @@ fe_remove_pressed(GtkWidget * widget, gpointer throwaway)
static void
change_filter_name(gchar * old_name,gchar * new_name)
{
- if (!new_name || strcmp(old_name,new_name)!=0) {
+ if (g_strcmp0(old_name,new_name)!=0) {
GList * lst;
filters_names_rec * p=NULL;
@@ -1672,13 +1672,15 @@ change_filter_name(gchar * old_name,gchar * new_name)
if yes we must change it to : any name -> new_name
else we create a new record
*/
- for (lst=filters_names_changes;lst;lst=g_list_next(lst))
- if (((filters_names_rec *)lst->data)->new_name &&
- strcmp(((filters_names_rec *)lst->data)->new_name,old_name)==0) {
- p=(filters_names_rec *)lst->data;
+ for (lst=filters_names_changes;lst;lst=g_list_next(lst)) {
+ filters_names_rec *q = lst->data;
+
+ if (g_strcmp0(q->new_name, old_name) == 0) {
+ p = q;
g_free(p->new_name);
break;
}
+ }
if (!lst) {
/* New name change, create record */
p=g_new(filters_names_rec,1);
@@ -1688,7 +1690,7 @@ change_filter_name(gchar * old_name,gchar * new_name)
/* Record exists yet, test if we can collapse it (in case his
* old_name==new_name) It's only a small optimization
*/
- else if (new_name && strcmp(p->old_name,new_name)==0) {
+ else if (g_strcmp0(p->old_name,new_name)==0) {
g_free(p->old_name);
g_free(p);
filters_names_changes=
diff --git a/src/folder-conf.c b/src/folder-conf.c
index 262742a98..d609a1bff 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -635,11 +635,11 @@ subfolder_conf_clicked_ok(SubfolderDialogData * sdd)
mailbox_conf_view_check(sdd->mcv, sdd->mbnode->mailbox);
/* rename */
- if ((sdd->old_parent && strcmp(parent, sdd->old_parent)) ||
- (sdd->old_folder && strcmp(folder, sdd->old_folder))) {
+ if (g_strcmp0(parent, sdd->old_parent) != 0 ||
+ g_strcmp0(folder, sdd->old_folder) != 0) {
gint button = GTK_RESPONSE_OK;
- if (sdd->old_folder && !strcmp(sdd->old_folder, "INBOX") &&
- (!sdd->old_parent || !*sdd->old_parent)) {
+ if (g_strcmp0(sdd->old_folder, "INBOX") == 0 &&
+ (sdd->old_parent == NULL || sdd->old_parent[0] == '\0')) {
gchar *msg =
g_strdup_printf(_
("Renaming Inbox is special!\n"
@@ -904,7 +904,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
/* my rights */
for (n = 0;
- std_acls[n] && strcmp(std_acls[n], rights);
+ g_strcmp0(std_acls[n], rights) != 0;
n += 2);
rights_str = g_string_new(_("mine: "));
if (std_acls[n])
@@ -920,7 +920,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
for (uid = 0; acls[uid]; uid += 2) {
for (n = 0;
- std_acls[n] && strcmp(std_acls[n], acls[uid + 1]);
+ g_strcmp0(std_acls[n], acls[uid + 1]) != 0;
n += 2);
if (std_acls[n])
g_string_append_printf(rights_str,
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index 5a04d8f81..c6a746b8a 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -1178,15 +1178,15 @@ remove_special_mailbox_by_url(const gchar* url, LibBalsaMailbox *** special)
{
LibBalsaMailbox **mailbox;
- if (balsa_app.trash && strcmp(url, balsa_app.trash->url) == 0)
+ if (g_strcmp0(url, balsa_app.trash->url) == 0)
mailbox = &balsa_app.trash;
- else if (balsa_app.inbox && strcmp(url, balsa_app.inbox->url) == 0)
+ else if (g_strcmp0(url, balsa_app.inbox->url) == 0)
mailbox = &balsa_app.inbox;
- else if (balsa_app.outbox && strcmp(url, balsa_app.outbox->url) == 0)
+ else if (g_strcmp0(url, balsa_app.outbox->url) == 0)
mailbox = &balsa_app.outbox;
- else if (balsa_app.sentbox && strcmp(url, balsa_app.sentbox->url) == 0)
+ else if (g_strcmp0(url, balsa_app.sentbox->url) == 0)
mailbox = &balsa_app.sentbox;
- else if (balsa_app.draftbox && strcmp(url, balsa_app.draftbox->url) == 0)
+ else if (g_strcmp0(url, balsa_app.draftbox->url) == 0)
mailbox = &balsa_app.draftbox;
else
mailbox = NULL;
diff --git a/src/pref-manager.c b/src/pref-manager.c
index fb0ffae1a..9e2544fdf 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -3232,7 +3232,7 @@ open_preferences_manager_idle(void)
name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER
(pui->mail_directory));
- if (!name || strcmp(name, balsa_app.local_mail_directory) != 0) {
+ if (g_strcmp0(name, balsa_app.local_mail_directory) != 0) {
/* Chooser still hasn't been initialized. */
g_free(name);
return TRUE;
diff --git a/src/save-restore.c b/src/save-restore.c
index 590651654..48fbf1927 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -1529,8 +1529,7 @@ config_address_book_load(const gchar * key, const gchar * value,
balsa_app.address_book_list =
g_list_prepend(balsa_app.address_book_list, address_book);
- if (default_address_book_prefix
- && strcmp(key, default_address_book_prefix) == 0) {
+ if (g_strcmp0(key, default_address_book_prefix) == 0) {
balsa_app.default_address_book = address_book;
}
}
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 6ffed7f92..cc8fc3059 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -226,8 +226,7 @@ sw_preferred_charset(BalsaSendmsg * bsmsg)
guint i;
for (i = 0; i < G_N_ELEMENTS(locales); i++)
- if (bsmsg->spell_check_lang && locales[i].locale
- && strcmp(bsmsg->spell_check_lang, locales[i].locale) == 0)
+ if (g_strcmp0(bsmsg->spell_check_lang, locales[i].locale) == 0)
return locales[i].charset;
return NULL;
@@ -680,7 +679,7 @@ find_locale_index_by_locale(const gchar * locale)
unsigned i, j, maxfit = 0;
gint maxpos = -1;
- if (!locale || strcmp(locale, "C") == 0)
+ if (locale == NULL || strcmp(locale, "C") == 0)
locale = "en_US";
for (i = 0; i < ELEMENTS(locales); i++) {
for (j = 0; locale[j] && locales[i].locale[j] == locale[j]; j++);
@@ -2750,7 +2749,7 @@ has_file_attached(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
if (!info)
return FALSE;
uri = libbalsa_vfs_get_uri(info->file_uri);
- if (uri && !strcmp(find_file->name, uri))
+ if (g_strcmp0(find_file->name, uri) == 0)
find_file->found = TRUE;
g_object_unref(info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]