From 2b3cc65b52ecc9de54c6d4974f8253ce1fbcf3bd Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:16:39 +0100 Subject: [PATCH 01/35] Use null check convention in command.c --- src/command/command.c | 220 +++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index fca25690..04bb6603 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1247,7 +1247,7 @@ cmd_init(void) // load aliases GList *aliases = prefs_get_aliases(); GList *curr = aliases; - while (curr != NULL) { + while (curr) { ProfAlias *alias = curr->data; GString *ac_alias = g_string_new("/"); g_string_append(ac_alias, alias->name); @@ -1645,7 +1645,7 @@ cmd_exists(char *cmd) void cmd_autocomplete_add(char *value) { - if (commands_ac != NULL) { + if (commands_ac) { autocomplete_add(commands_ac, value); } } @@ -1687,7 +1687,7 @@ cmd_autocomplete_remove_form_fields(DataForm *form) void cmd_autocomplete_remove(char *value) { - if (commands_ac != NULL) { + if (commands_ac) { autocomplete_remove(commands_ac, value); } } @@ -1695,7 +1695,7 @@ cmd_autocomplete_remove(char *value) void cmd_alias_add(char *value) { - if (aliases_ac != NULL) { + if (aliases_ac) { autocomplete_add(aliases_ac, value); } } @@ -1703,7 +1703,7 @@ cmd_alias_add(char *value) void cmd_alias_remove(char *value) { - if (aliases_ac != NULL) { + if (aliases_ac) { autocomplete_remove(aliases_ac, value); } } @@ -1716,7 +1716,7 @@ cmd_autocomplete(const char * const input) if ((strncmp(input, "/", 1) == 0) && (!str_contains(input, strlen(input), ' '))) { char *found = NULL; found = autocomplete_complete(commands_ac, input, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -1756,7 +1756,7 @@ cmd_reset_autocomplete() autocomplete_reset(autoaway_mode_ac); autocomplete_reset(autoconnect_ac); autocomplete_reset(theme_ac); - if (theme_load_ac != NULL) { + if (theme_load_ac) { autocomplete_free(theme_load_ac); theme_load_ac = NULL; } @@ -1887,7 +1887,7 @@ _cmd_execute(const char * const command, const char * const inp) Command *cmd = g_hash_table_lookup(commands, command); gboolean result = FALSE; - if (cmd != NULL) { + if (cmd) { gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result); if (result == FALSE) { ui_invalid_command_usage(cmd->help.usage, cmd->setting_func); @@ -2034,7 +2034,7 @@ _cmd_complete_parameters(const char * const input) parsed[i] = '\0'; char * (*ac_func)(const char * const) = g_hash_table_lookup(ac_funcs, parsed); - if (ac_func != NULL) { + if (ac_func) { result = ac_func(input); if (result) { g_hash_table_destroy(ac_funcs); @@ -2058,15 +2058,15 @@ _sub_autocomplete(const char * const input) { char *result = NULL; result = autocomplete_param_with_func(input, "/sub allow", presence_sub_request_find); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/sub deny", presence_sub_request_find); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/sub", sub_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2081,7 +2081,7 @@ _who_autocomplete(const char * const input) if (win_type == WIN_MUC) { result = autocomplete_param_with_ac(input, "/who", who_room_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } else { @@ -2092,13 +2092,13 @@ _who_autocomplete(const char * const input) for (i = 0; i < ARRAY_SIZE(group_commands); i++) { result = autocomplete_param_with_func(input, group_commands[i], roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } } result = autocomplete_param_with_ac(input, "/who", who_roster_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } @@ -2111,31 +2111,31 @@ _roster_autocomplete(const char * const input) { char *result = NULL; result = autocomplete_param_with_func(input, "/roster nick", roster_barejid_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/roster clearnick", roster_barejid_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/roster remove", roster_barejid_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster show", roster_option_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster hide", roster_option_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster by", roster_by_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2147,28 +2147,28 @@ _group_autocomplete(const char * const input) { char *result = NULL; result = autocomplete_param_with_func(input, "/group show", roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_no_with_func(input, "/group add", 4, roster_contact_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_no_with_func(input, "/group remove", 4, roster_contact_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/group add", roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/group remove", roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/group", group_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2229,7 +2229,7 @@ _bookmark_autocomplete(const char * const input) found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE); } g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2238,15 +2238,15 @@ _bookmark_autocomplete(const char * const input) g_strfreev(args); found = autocomplete_param_with_func(input, "/bookmark remove", bookmark_find); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/bookmark join", bookmark_find); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/bookmark update", bookmark_find); - if (found != NULL) { + if (found) { return found; } @@ -2261,42 +2261,42 @@ _notify_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_func(input, "/notify room current", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify message current", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify typing current", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify room text", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify message text", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/notify room", notify_room_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/notify message", notify_message_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/notify typing", notify_typing_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2304,13 +2304,13 @@ _notify_autocomplete(const char * const input) for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } } result = autocomplete_param_with_ac(input, "/notify", notify_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2323,16 +2323,16 @@ _autoaway_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_ac(input, "/autoaway mode", autoaway_mode_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/autoaway check", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/autoaway", autoaway_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2346,16 +2346,16 @@ _log_autocomplete(const char * const input) result = autocomplete_param_with_func(input, "/log rotate", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/log shared", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/log", log_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2368,12 +2368,12 @@ _autoconnect_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_func(input, "/autoconnect set", accounts_find_enabled); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/autoconnect", autoconnect_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2386,12 +2386,12 @@ _otr_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_func(input, "/otr start", roster_contact_autocomplete); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/otr log", otr_log_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2406,7 +2406,7 @@ _otr_autocomplete(const char * const input) found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2415,18 +2415,18 @@ _otr_autocomplete(const char * const input) g_strfreev(args); found = autocomplete_param_with_ac(input, "/otr policy", otr_policy_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/otr warn", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/otr", otr_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2442,7 +2442,7 @@ _theme_autocomplete(const char * const input) theme_load_ac = autocomplete_new(); GSList *themes = theme_list(); GSList *curr = themes; - while (curr != NULL) { + while (curr) { autocomplete_add(theme_load_ac, curr->data); curr = g_slist_next(curr); } @@ -2450,12 +2450,12 @@ _theme_autocomplete(const char * const input) autocomplete_add(theme_load_ac, "default"); } result = autocomplete_param_with_ac(input, "/theme load", theme_load_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } result = autocomplete_param_with_ac(input, "/theme", theme_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2474,24 +2474,24 @@ _resource_autocomplete(const char * const input) if (contact) { Autocomplete ac = p_contact_resource_ac(contact); found = autocomplete_param_with_ac(input, "/resource set", ac, FALSE); - if (found != NULL) { + if (found) { return found; } } } found = autocomplete_param_with_func(input, "/resource title", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/resource message", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/resource", resource_ac, FALSE); - if (found != NULL) { + if (found) { return found; } @@ -2504,17 +2504,17 @@ _titlebar_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_func(input, "/titlebar show", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/titlebar goodbye", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/titlebar", titlebar_ac, FALSE); - if (found != NULL) { + if (found) { return found; } @@ -2527,12 +2527,12 @@ _inpblock_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_func(input, "/inpblock dynamic", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/inpblock", inpblock_ac, FALSE); - if (found != NULL) { + if (found) { return found; } @@ -2553,13 +2553,13 @@ _form_autocomplete(const char * const input) DataForm *form = confwin->form; if (form) { found = autocomplete_param_with_ac(input, "/form help", form->tag_ac, TRUE); - if (found != NULL) { + if (found) { return found; } } found = autocomplete_param_with_ac(input, "/form", form_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2643,32 +2643,32 @@ _occupants_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_ac(input, "/occupants default show", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants default hide", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants default", occupants_default_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants show", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants hide", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants", occupants_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2681,12 +2681,12 @@ _time_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_ac(input, "/time statusbar", time_statusbar_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/time", time_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2702,9 +2702,9 @@ _kick_autocomplete(const char * const input) ProfMucWin *mucwin = wins_get_current_muc(); Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid); - if (nick_ac != NULL) { + if (nick_ac) { result = autocomplete_param_with_ac(input, "/kick", nick_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } @@ -2722,9 +2722,9 @@ _ban_autocomplete(const char * const input) ProfMucWin *mucwin = wins_get_current_muc(); Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid); - if (jid_ac != NULL) { + if (jid_ac) { result = autocomplete_param_with_ac(input, "/ban", jid_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } @@ -2753,7 +2753,7 @@ _affiliation_autocomplete(const char * const input) result = autocomplete_param_with_ac(input, beginning->str, jid_ac, TRUE); g_string_free(beginning, TRUE); - if (result != NULL) { + if (result) { g_strfreev(args); return result; } @@ -2763,17 +2763,17 @@ _affiliation_autocomplete(const char * const input) } result = autocomplete_param_with_ac(input, "/affiliation set", affiliation_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/affiliation list", affiliation_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/affiliation", privilege_cmd_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2800,7 +2800,7 @@ _role_autocomplete(const char * const input) result = autocomplete_param_with_ac(input, beginning->str, nick_ac, TRUE); g_string_free(beginning, TRUE); - if (result != NULL) { + if (result) { g_strfreev(args); return result; } @@ -2810,17 +2810,17 @@ _role_autocomplete(const char * const input) } result = autocomplete_param_with_ac(input, "/role set", role_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/role list", role_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/role", privilege_cmd_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2833,22 +2833,22 @@ _statuses_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_ac(input, "/statuses console", statuses_setting_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/statuses chat", statuses_setting_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/statuses muc", statuses_setting_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/statuses", statuses_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2861,17 +2861,17 @@ _receipts_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_func(input, "/receipts send", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/receipts request", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/receipts", receipts_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2884,12 +2884,12 @@ _alias_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_ac(input, "/alias remove", aliases_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/alias", alias_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2907,7 +2907,7 @@ _connect_autocomplete(const char * const input) if ((strncmp(input, "/connect", 8) == 0) && (result == TRUE)) { GString *beginning = g_string_new("/connect "); g_string_append(beginning, args[0]); - if (args[1] != NULL && args[2] != NULL) { + if (args[1] && args[2]) { g_string_append(beginning, " "); g_string_append(beginning, args[1]); g_string_append(beginning, " "); @@ -2915,7 +2915,7 @@ _connect_autocomplete(const char * const input) } found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2924,7 +2924,7 @@ _connect_autocomplete(const char * const input) g_strfreev(args); found = autocomplete_param_with_func(input, "/connect", accounts_find_enabled); - if (found != NULL) { + if (found) { return found; } @@ -2938,7 +2938,7 @@ _join_autocomplete(const char * const input) gboolean result = FALSE; found = autocomplete_param_with_func(input, "/join", bookmark_find); - if (found != NULL) { + if (found) { return found; } @@ -2947,7 +2947,7 @@ _join_autocomplete(const char * const input) if ((strncmp(input, "/join", 5) == 0) && (result == TRUE)) { GString *beginning = g_string_new("/join "); g_string_append(beginning, args[0]); - if (args[1] != NULL && args[2] != NULL) { + if (args[1] && args[2]) { g_string_append(beginning, " "); g_string_append(beginning, args[1]); g_string_append(beginning, " "); @@ -2955,7 +2955,7 @@ _join_autocomplete(const char * const input) } found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2982,14 +2982,14 @@ _account_autocomplete(const char * const input) g_string_append(beginning, args[2]); found = autocomplete_param_with_ac(input, beginning->str, otr_policy_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } } else { found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -3001,7 +3001,7 @@ _account_autocomplete(const char * const input) g_string_append(beginning, args[1]); found = autocomplete_param_with_ac(input, beginning->str, account_clear_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -3021,7 +3021,7 @@ _account_autocomplete(const char * const input) for (i = 0; i < ARRAY_SIZE(account_choice); i++) { found = autocomplete_param_with_func(input, account_choice[i], accounts_find_all); - if (found != NULL) { + if (found) { return found; } } @@ -3066,7 +3066,7 @@ command_docgen(void) fputs("

Details:

\n", main_fragment); fputs("

", main_fragment);
         int i = 2;
-        while (pcmd->help.long_help[i] != NULL) {
+        while (pcmd->help.long_help[i]) {
             fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
         }
         fputs("

\n
back to top


\n", main_fragment); From 4acf853b1c66a9fbc4b80d75144ea7dd01b6471d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:23:59 +0100 Subject: [PATCH 02/35] Use null check convention in commands.c --- src/command/commands.c | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index dfabc4f0..3d7dcc67 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -404,7 +404,7 @@ cmd_account(gchar **args, struct cmd_help_t help) } else { accounts_set_jid(account_name, jid->barejid); cons_show("Updated jid for account %s: %s", account_name, jid->barejid); - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { accounts_set_resource(account_name, jid->resourcepart); cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart); } @@ -434,7 +434,7 @@ cmd_account(gchar **args, struct cmd_help_t help) cons_show("Updated resource for account %s: %s", account_name, value); cons_show(""); } else if (strcmp(property, "password") == 0) { - if(accounts_get_account(account_name)->eval_password != NULL) { + if(accounts_get_account(account_name)->eval_password) { cons_show("Cannot set password when eval_password is set."); } else { accounts_set_password(account_name, value); @@ -442,7 +442,7 @@ cmd_account(gchar **args, struct cmd_help_t help) cons_show(""); } } else if (strcmp(property, "eval_password") == 0) { - if(accounts_get_account(account_name)->password != NULL) { + if(accounts_get_account(account_name)->password) { cons_show("Cannot set eval_password when password is set."); } else { accounts_set_eval_password(account_name, value); @@ -755,7 +755,7 @@ cmd_help(gchar **args, struct cmd_help_t help) } GList *curr = ordered_commands; - while (curr != NULL) { + while (curr) { Command *cmd = curr->data; cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); curr = g_list_next(curr); @@ -817,12 +817,12 @@ cmd_help(gchar **args, struct cmd_help_t help) const gchar **help_text = NULL; Command *command = g_hash_table_lookup(commands, cmd_with_slash); - if (command != NULL) { + if (command) { help_text = command->help.long_help; } cons_show(""); - if (help_text != NULL) { + if (help_text) { ProfWin *console = wins_get_console(); ui_show_lines(console, help_text); } else { @@ -928,13 +928,13 @@ cmd_theme(gchar **args, struct cmd_help_t help) static void _who_room(gchar **args, struct cmd_help_t help) { - if ((g_strv_length(args) == 2) && (args[1] != NULL)) { + if ((g_strv_length(args) == 2) && args[1]) { cons_show("Argument group is not applicable to chat rooms."); return; } // bad arg - if (args[0] != NULL && + if (args[0] && (g_strcmp0(args[0], "online") != 0) && (g_strcmp0(args[0], "available") != 0) && (g_strcmp0(args[0], "unavailable") != 0) && @@ -978,7 +978,7 @@ _who_room(gchar **args, struct cmd_help_t help) } else if (strcmp("available", presence) == 0) { GList *filtered = NULL; - while (occupants != NULL) { + while (occupants) { Occupant *occupant = occupants->data; if (muc_occupant_available(occupant)) { filtered = g_list_append(filtered, occupant); @@ -992,7 +992,7 @@ _who_room(gchar **args, struct cmd_help_t help) } else if (strcmp("unavailable", presence) == 0) { GList *filtered = NULL; - while (occupants != NULL) { + while (occupants) { Occupant *occupant = occupants->data; if (!muc_occupant_available(occupant)) { filtered = g_list_append(filtered, occupant); @@ -1006,7 +1006,7 @@ _who_room(gchar **args, struct cmd_help_t help) } else { GList *filtered = NULL; - while (occupants != NULL) { + while (occupants) { Occupant *occupant = occupants->data; const char *presence_str = string_from_resource_presence(occupant->presence); if (strcmp(presence_str, presence) == 0) { @@ -1060,7 +1060,7 @@ _who_roster(gchar **args, struct cmd_help_t help) char *presence = args[0]; // bad arg - if ((presence != NULL) + if (presence && (strcmp(presence, "online") != 0) && (strcmp(presence, "available") != 0) && (strcmp(presence, "unavailable") != 0) @@ -1075,13 +1075,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } char *group = NULL; - if ((g_strv_length(args) == 2) && (args[1] != NULL)) { + if ((g_strv_length(args) == 2) && args[1]) { group = args[1]; } cons_show(""); GSList *list = NULL; - if (group != NULL) { + if (group) { list = roster_get_group(group); if (list == NULL) { cons_show("No such group: %s.", group); @@ -1097,7 +1097,7 @@ _who_roster(gchar **args, struct cmd_help_t help) // no arg, show all contacts if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { - if (group != NULL) { + if (group) { if (list == NULL) { cons_show("No contacts in group %s.", group); } else { @@ -1118,7 +1118,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (p_contact_is_available(contact)) { filtered = g_slist_append(filtered, contact); @@ -1126,7 +1126,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1148,7 +1148,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (!p_contact_is_available(contact)) { filtered = g_slist_append(filtered, contact); @@ -1156,7 +1156,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1178,7 +1178,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (p_contact_has_available_resource(contact)) { filtered = g_slist_append(filtered, contact); @@ -1186,7 +1186,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1208,7 +1208,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (!p_contact_has_available_resource(contact)) { filtered = g_slist_append(filtered, contact); @@ -1216,7 +1216,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1238,7 +1238,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (strcmp(p_contact_presence(contact), presence) == 0) { filtered = g_slist_append(filtered, contact); @@ -1246,7 +1246,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1369,9 +1369,9 @@ cmd_group(gchar **args, struct cmd_help_t help) if (args[0] == NULL) { GSList *groups = roster_get_groups(); GSList *curr = groups; - if (curr != NULL) { + if (curr) { cons_show("Groups:"); - while (curr != NULL) { + while (curr) { cons_show(" %s", curr->data); curr = g_slist_next(curr); } @@ -1739,7 +1739,7 @@ cmd_status(gchar **args, struct cmd_help_t help) switch (win_type) { case WIN_MUC: - if (usr != NULL) { + if (usr) { ProfMucWin *mucwin = wins_get_current_muc(); ProfWin *window = (ProfWin*) mucwin; Occupant *occupant = muc_roster_item(mucwin->roomjid, usr); @@ -1753,13 +1753,13 @@ cmd_status(gchar **args, struct cmd_help_t help) } break; case WIN_CHAT: - if (usr != NULL) { + if (usr) { ui_current_print_line("No parameter required when in chat."); } else { ProfChatWin *chatwin = wins_get_current_chat(); ProfWin *window = (ProfWin*) chatwin; PContact pcontact = roster_get_contact(chatwin->barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_contact(window, pcontact); } else { win_println(window, "Error getting contact info."); @@ -1767,7 +1767,7 @@ cmd_status(gchar **args, struct cmd_help_t help) } break; case WIN_PRIVATE: - if (usr != NULL) { + if (usr) { ui_current_print_line("No parameter required when in chat."); } else { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -1783,7 +1783,7 @@ cmd_status(gchar **args, struct cmd_help_t help) } break; case WIN_CONSOLE: - if (usr != NULL) { + if (usr) { char *usr_jid = roster_barejid_from_name(usr); if (usr_jid == NULL) { usr_jid = usr; @@ -1840,7 +1840,7 @@ cmd_info(gchar **args, struct cmd_help_t help) ProfChatWin *chatwin = wins_get_current_chat(); ProfWin *window = (ProfWin*) chatwin; PContact pcontact = roster_get_contact(chatwin->barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_info(window, pcontact); } else { win_println(window, "Error getting contact info."); @@ -1870,7 +1870,7 @@ cmd_info(gchar **args, struct cmd_help_t help) usr_jid = usr; } pcontact = roster_get_contact(usr_jid); - if (pcontact != NULL) { + if (pcontact) { cons_show_info(pcontact); } else { cons_show("No such contact \"%s\" in roster.", usr); @@ -1902,7 +1902,7 @@ cmd_caps(gchar **args, struct cmd_help_t help) switch (win_type) { case WIN_MUC: - if (args[0] != NULL) { + if (args[0]) { ProfMucWin *mucwin = wins_get_current_muc(); occupant = muc_roster_item(mucwin->roomjid, args[0]); if (occupant) { @@ -1918,7 +1918,7 @@ cmd_caps(gchar **args, struct cmd_help_t help) break; case WIN_CHAT: case WIN_CONSOLE: - if (args[0] != NULL) { + if (args[0]) { Jid *jid = jid_create(args[0]); if (jid->fulljid == NULL) { @@ -1942,7 +1942,7 @@ cmd_caps(gchar **args, struct cmd_help_t help) } break; case WIN_PRIVATE: - if (args[0] != NULL) { + if (args[0]) { cons_show("No parameter needed to /caps when in private chat."); } else { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -1977,7 +1977,7 @@ cmd_software(gchar **args, struct cmd_help_t help) switch (win_type) { case WIN_MUC: - if (args[0] != NULL) { + if (args[0]) { ProfMucWin *mucwin = wins_get_current_muc(); occupant = muc_roster_item(mucwin->roomjid, args[0]); if (occupant) { @@ -1993,7 +1993,7 @@ cmd_software(gchar **args, struct cmd_help_t help) break; case WIN_CHAT: case WIN_CONSOLE: - if (args[0] != NULL) { + if (args[0]) { Jid *jid = jid_create(args[0]); if (jid == NULL || jid->fulljid == NULL) { @@ -2007,7 +2007,7 @@ cmd_software(gchar **args, struct cmd_help_t help) } break; case WIN_PRIVATE: - if (args[0] != NULL) { + if (args[0]) { cons_show("No parameter needed to /software when in private chat."); } else { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -2067,7 +2067,7 @@ cmd_join(gchar **args, struct cmd_help_t help) ProfAccount *account = accounts_get_account(account_name); // full room jid supplied (room@server) - if (room_arg->localpart != NULL) { + if (room_arg->localpart) { room = args[0]; // server not supplied (room), use account preference @@ -2142,7 +2142,7 @@ cmd_invite(gchar **args, struct cmd_help_t help) ProfMucWin *mucwin = wins_get_current_muc(); message_send_invite(mucwin->roomjid, usr_jid, reason); - if (reason != NULL) { + if (reason) { cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", contact, mucwin->roomjid, reason); } else { @@ -2427,7 +2427,7 @@ cmd_form(gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "help") == 0) { char *tag = args[1]; - if (tag != NULL) { + if (tag) { ui_show_form_field_help(confwin, tag); } else { ui_show_form_help(confwin); @@ -2435,7 +2435,7 @@ cmd_form(gchar **args, struct cmd_help_t help) const gchar **help_text = NULL; Command *command = g_hash_table_lookup(commands, "/form"); - if (command != NULL) { + if (command) { help_text = command->help.long_help; } @@ -2601,7 +2601,7 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) } char *affiliation = args[1]; - if ((affiliation != NULL) && + if (affiliation && (g_strcmp0(affiliation, "owner") != 0) && (g_strcmp0(affiliation, "admin") != 0) && (g_strcmp0(affiliation, "member") != 0) && @@ -2671,7 +2671,7 @@ cmd_role(gchar **args, struct cmd_help_t help) } char *role = args[1]; - if ((role != NULL ) && + if (role && (g_strcmp0(role, "visitor") != 0) && (g_strcmp0(role, "participant") != 0) && (g_strcmp0(role, "moderator") != 0) && @@ -2961,7 +2961,7 @@ cmd_bookmark(gchar **args, struct cmd_help_t help) char *password = g_hash_table_lookup(options, "password"); char *autojoin = g_hash_table_lookup(options, "autojoin"); - if (autojoin != NULL) { + if (autojoin) { if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) { cons_show("Usage: %s", help.usage); cons_show(""); @@ -3009,7 +3009,7 @@ cmd_disco(gchar **args, struct cmd_help_t help) } GString *jid = g_string_new(""); - if (args[1] != NULL) { + if (args[1]) { jid = g_string_append(jid, args[1]); } else { Jid *jidp = jid_create(jabber_get_fulljid()); @@ -4164,7 +4164,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) return TRUE; } else if (strcmp(args[0], "start") == 0) { - if (args[1] != NULL) { + if (args[1]) { char *contact = args[1]; char *barejid = roster_barejid_from_name(contact); if (barejid == NULL) { @@ -4383,7 +4383,7 @@ _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) } GList *curr = ordered_commands; - while (curr != NULL) { + while (curr) { Command *cmd = curr->data; cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); curr = g_list_next(curr); From 47549452f178a9a81a5481e87d8004ce6010e3c1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:29:51 +0100 Subject: [PATCH 03/35] Use null check convention in account.c --- src/config/account.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config/account.c b/src/config/account.c index 749eb885..857d049b 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -57,19 +57,19 @@ account_new(const gchar * const name, const gchar * const jid, new_account->name = strdup(name); - if (jid != NULL) { + if (jid) { new_account->jid = strdup(jid); } else { new_account->jid = strdup(name); } - if (password != NULL) { + if (password) { new_account->password = strdup(password); } else { new_account->password = NULL; } - if (eval_password != NULL) { + if (eval_password) { new_account->eval_password = strdup(eval_password); } else { new_account->eval_password = NULL; @@ -77,13 +77,13 @@ account_new(const gchar * const name, const gchar * const jid, new_account->enabled = enabled; - if (server != NULL) { + if (server) { new_account->server = strdup(server); } else { new_account->server = NULL; } - if (resource != NULL) { + if (resource) { new_account->resource = strdup(resource); } else { new_account->resource = NULL; @@ -134,7 +134,7 @@ account_new(const gchar * const name, const gchar * const jid, new_account->muc_nick = strdup(muc_nick); } - if (otr_policy != NULL) { + if (otr_policy) { new_account->otr_policy = strdup(otr_policy); } else { new_account->otr_policy = NULL; @@ -150,7 +150,7 @@ account_new(const gchar * const name, const gchar * const jid, char * account_create_full_jid(ProfAccount *account) { - if (account->resource != NULL) { + if (account->resource) { return create_fulljid(account->jid, account->resource); } else { return strdup(account->jid); @@ -198,7 +198,7 @@ account_eval_password(ProfAccount *account) void account_free(ProfAccount *account) { - if (account != NULL) { + if (account) { free(account->name); free(account->jid); free(account->password); From a293045d855ab04aa9beff7924e1f5ec2d0403fc Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:32:42 +0100 Subject: [PATCH 04/35] Use null check convention in accounts.c --- src/config/accounts.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index 6c04549c..d68f3a55 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -147,9 +147,9 @@ accounts_add(const char *account_name, const char *altdomain, const int port) const char *barejid = account_name; const char *resource = "profanity"; Jid *jid = jid_create(account_name); - if (jid != NULL) { + if (jid) { barejid = jid->barejid; - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { resource = jid->resourcepart; } } @@ -159,7 +159,7 @@ accounts_add(const char *account_name, const char *altdomain, const int port) g_key_file_set_boolean(accounts, account_name, "enabled", TRUE); g_key_file_set_string(accounts, account_name, "jid", barejid); g_key_file_set_string(accounts, account_name, "resource", resource); - if (altdomain != NULL) { + if (altdomain) { g_key_file_set_string(accounts, account_name, "server", altdomain); } if (port != 0) { @@ -252,7 +252,7 @@ accounts_get_account(const char * const name) gsize length; GList *otr_manual = NULL; gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL); - if (manual != NULL) { + if (manual) { int i = 0; for (i = 0; i < length; i++) { otr_manual = g_list_append(otr_manual, strdup(manual[i])); @@ -262,7 +262,7 @@ accounts_get_account(const char * const name) GList *otr_opportunistic = NULL; gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL); - if (opportunistic != NULL) { + if (opportunistic) { int i = 0; for (i = 0; i < length; i++) { otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i])); @@ -272,7 +272,7 @@ accounts_get_account(const char * const name) GList *otr_always = NULL; gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL); - if (always != NULL) { + if (always) { int i = 0; for (i = 0; i < length; i++) { otr_always = g_list_append(otr_always, strdup(always[i])); @@ -356,7 +356,7 @@ accounts_rename(const char * const account_name, const char * const new_name) int i; for (i = 0; i < ARRAY_SIZE(string_keys); i++) { char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL); - if (value != NULL) { + if (value) { g_key_file_set_string(accounts, new_name, string_keys[i], value); g_free(value); } @@ -386,10 +386,10 @@ void accounts_set_jid(const char * const account_name, const char * const value) { Jid *jid = jid_create(value); - if (jid != NULL) { + if (jid) { if (accounts_account_exists(account_name)) { g_key_file_set_string(accounts, account_name, "jid", jid->barejid); - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart); } @@ -509,7 +509,7 @@ accounts_add_otr_policy(const char * const account_name, const char * const cont GList *glist = NULL; // list found - if (list != NULL) { + if (list) { int i = 0; for (i = 0; i < length; i++) { // item already in list, exit function @@ -529,7 +529,7 @@ accounts_add_otr_policy(const char * const account_name, const char * const cont const gchar* new_list[g_list_length(glist)+1]; GList *curr = glist; i = 0; - while (curr != NULL) { + while (curr) { new_list[i++] = strdup(curr->data); curr = g_list_next(curr); } @@ -572,7 +572,7 @@ _remove_from_list(GKeyFile *accounts, const char * const account_name, const cha gsize length; gchar **list = g_key_file_get_string_list(accounts, account_name, key, &length, NULL); - if (list != NULL) { + if (list) { int i = 0; GList *glist = NULL; gboolean deleted = FALSE; @@ -595,7 +595,7 @@ _remove_from_list(GKeyFile *accounts, const char * const account_name, const cha const gchar* new_list[g_list_length(glist)+1]; GList *curr = glist; i = 0; - while (curr != NULL) { + while (curr) { new_list[i++] = strdup(curr->data); curr = g_list_next(curr); } @@ -766,7 +766,7 @@ accounts_get_last_presence(const char * const account_name) result = RESOURCE_ONLINE; } - if (setting != NULL) { + if (setting) { g_free(setting); } return result; @@ -796,7 +796,7 @@ accounts_get_login_presence(const char * const account_name) result = RESOURCE_ONLINE; } - if (setting != NULL) { + if (setting) { g_free(setting); } return result; @@ -809,9 +809,9 @@ _fix_legacy_accounts(const char * const account_name) const char *barejid = account_name; const char *resource = "profanity"; Jid *jid = jid_create(account_name); - if (jid != NULL) { + if (jid) { barejid = jid->barejid; - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { resource = jid->resourcepart; } } From b093b99c15c109eb56f0386f8add5529b5e76a4c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:33:19 +0100 Subject: [PATCH 05/35] Use null check convention in preferences.c --- src/config/preferences.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 3ca3a721..59a6a7ca 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -95,7 +95,7 @@ prefs_load(void) err = NULL; log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); - if (err != NULL) { + if (err) { log_maxsize = 0; g_error_free(err); } @@ -180,7 +180,7 @@ prefs_get_string(preference_t pref) char *result = g_key_file_get_string(prefs, group, key, NULL); if (result == NULL) { - if (def != NULL) { + if (def) { return strdup(def); } else { return NULL; @@ -193,7 +193,7 @@ prefs_get_string(preference_t pref) void prefs_free_string(char *pref) { - if (pref != NULL) { + if (pref) { free(pref); } pref = NULL; @@ -419,7 +419,7 @@ prefs_get_aliases(void) char *name = keys[i]; char *value = g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL); - if (value != NULL) { + if (value) { ProfAlias *alias = malloc(sizeof(struct prof_alias_t)); alias->name = strdup(name); alias->value = strdup(value); From 4ba33005d0e5333ff15d9af40663741f6884c649 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:33:55 +0100 Subject: [PATCH 06/35] Use null check convention in theme.c --- src/config/theme.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config/theme.c b/src/config/theme.c index 1ee9836b..f73dee19 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -160,7 +160,7 @@ _theme_load_file(const char * const theme_name) { // use default theme if (theme_name == NULL || strcmp(theme_name, "default") == 0) { - if (theme != NULL) { + if (theme) { g_key_file_free(theme); } theme = g_key_file_new(); @@ -173,12 +173,12 @@ _theme_load_file(const char * const theme_name) return FALSE; } - if (theme_loc != NULL) { + if (theme_loc) { g_string_free(theme_loc, TRUE); } theme_loc = new_theme_file; log_info("Loading theme \"%s\"", theme_name); - if (theme != NULL) { + if (theme) { g_key_file_free(theme); } theme = g_key_file_new(); @@ -205,10 +205,10 @@ theme_list(void) void theme_close(void) { - if (theme != NULL) { + if (theme) { g_key_file_free(theme); } - if (theme_loc != NULL) { + if (theme_loc) { g_string_free(theme_loc, TRUE); } if (bold_items) { @@ -476,9 +476,9 @@ void _theme_list_dir(const gchar * const dir, GSList **result) { GDir *themes = g_dir_open(dir, 0, NULL); - if (themes != NULL) { + if (themes) { const gchar *theme = g_dir_read_name(themes); - while (theme != NULL) { + while (theme) { *result = g_slist_append(*result, strdup(theme)); theme = g_dir_read_name(themes); } @@ -492,7 +492,7 @@ _theme_find(const char * const theme_name) GString *path = NULL; gchar *themes_dir = _get_themes_dir(); - if (themes_dir != NULL) { + if (themes_dir) { path = g_string_new(themes_dir); g_free(themes_dir); g_string_append(path, "/"); From 4dc90334728b61f02ac3ee3508a663ae227b9fab Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:51:15 +0100 Subject: [PATCH 07/35] Use null check convention in server_events.c --- src/event/server_events.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 03d53901..e409e06a 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -63,9 +63,9 @@ sv_ev_login_account_success(char *account_name) // attempt to rejoin rooms with passwords GList *curr = muc_rooms(); - while (curr != NULL) { + while (curr) { char *password = muc_password(curr->data); - if (password != NULL) { + if (password) { char *nick = muc_nick(curr->data); presence_join_room(curr->data, nick, password); } @@ -271,7 +271,7 @@ sv_ev_contact_offline(char *barejid, char *resource, char *status) { gboolean updated = roster_contact_offline(barejid, resource, status); - if (resource != NULL && updated) { + if (resource && updated) { ui_contact_offline(barejid, resource, status); } @@ -289,7 +289,7 @@ sv_ev_contact_online(char *barejid, Resource *resource, char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE); char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); PContact contact = roster_get_contact(barejid); - if (p_contact_subscription(contact) != NULL) { + if (p_contact_subscription(contact)) { if (strcmp(p_contact_subscription(contact), "none") != 0) { // show in console if "all" @@ -441,14 +441,14 @@ sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean } char *subject = muc_subject(room); - if (subject != NULL) { + if (subject) { ui_room_subject(room, NULL, subject); } GList *pending_broadcasts = muc_pending_broadcasts(room); - if (pending_broadcasts != NULL) { + if (pending_broadcasts) { GList *curr = pending_broadcasts; - while (curr != NULL) { + while (curr) { ui_room_broadcast(room, curr->data); curr = g_list_next(curr); } From a979d23e10a5ad2ee25dab12c1fbbb66b5362a6e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:52:48 +0100 Subject: [PATCH 08/35] Use null check convention in otr.c --- src/otr/otr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/otr/otr.c b/src/otr/otr.c index fbc26eb8..e568af56 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -179,7 +179,7 @@ otr_init(void) void otr_shutdown(void) { - if (jid != NULL) { + if (jid) { free(jid); } } @@ -193,7 +193,7 @@ otr_poll(void) void otr_on_connect(ProfAccount *account) { - if (jid != NULL) { + if (jid) { free(jid); } jid = strdup(account->jid); @@ -360,7 +360,7 @@ otr_keygen(ProfAccount *account) return; } - if (jid != NULL) { + if (jid) { free(jid); } jid = strdup(account->jid); @@ -516,7 +516,7 @@ otr_trust(const char * const recipient) } if (context->active_fingerprint) { - if (context->active_fingerprint->trust != NULL) { + if (context->active_fingerprint->trust) { free(context->active_fingerprint->trust); } context->active_fingerprint->trust = strdup("trusted"); @@ -540,7 +540,7 @@ otr_untrust(const char * const recipient) } if (context->active_fingerprint) { - if (context->active_fingerprint->trust != NULL) { + if (context->active_fingerprint->trust) { free(context->active_fingerprint->trust); } context->active_fingerprint->trust = NULL; @@ -629,7 +629,7 @@ otr_get_their_fingerprint(const char * const recipient) { ConnContext *context = otrlib_context_find(user_state, recipient, jid); - if (context != NULL) { + if (context) { Fingerprint *fingerprint = context->active_fingerprint; char readable[45]; otrl_privkey_hash_to_human(readable, fingerprint->fingerprint); @@ -658,7 +658,7 @@ otr_get_policy(const char * const recipient) } // check default account setting - if (account->otr_policy != NULL) { + if (account->otr_policy) { prof_otrpolicy_t result; if (g_strcmp0(account->otr_policy, "manual") == 0) { result = PROF_OTRPOLICY_MANUAL; @@ -720,7 +720,7 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); if (tlv) { - if (context != NULL) { + if (context) { otrl_context_force_plaintext(context); ui_gone_insecure(from); } @@ -732,7 +732,7 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea return NULL; // message was decrypted, return to user - } else if (decrypted != NULL) { + } else if (decrypted) { *was_decrypted = TRUE; return decrypted; From 2426a7fcfcfa2ee4e5ab0f9300e7d5296170f893 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:55:04 +0100 Subject: [PATCH 09/35] Use null check convention in otrlibv3.c --- src/otr/otrlibv3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 77b0ee77..0b81796c 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -87,7 +87,7 @@ otrlib_end_session(OtrlUserState user_state, const char * const recipient, char ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp", 0, NULL, NULL, NULL); - if (context != NULL) { + if (context) { otrl_message_disconnect(user_state, ops, NULL, jid, "xmpp", recipient); } } @@ -171,7 +171,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; if (context->smstate->received_question == 0) { - if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) { + if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { ui_smp_successful(context->username); ui_trust(context->username); } else { @@ -193,7 +193,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext otrl_message_abort_smp(user_state, ops, NULL, context); } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) { + if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { ui_smp_successful(context->username); ui_trust(context->username); } else { From fa2e33e11d45e3df363da2c4ca3b2a6137f955df Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:55:28 +0100 Subject: [PATCH 10/35] Use null check convention in otrlibv4.c --- src/otr/otrlibv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 713e51ab..fc1f5285 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -253,7 +253,7 @@ otrlib_end_session(OtrlUserState user_state, const char * const recipient, char ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp", OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); - if (context != NULL) { + if (context) { otrl_message_disconnect(user_state, ops, NULL, jid, "xmpp", recipient, 0); } } From fe216b4e9777abe658c6a24e5c5faf5247e4b74d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:57:19 +0100 Subject: [PATCH 11/35] Use null check convention in parser.c --- src/tools/parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/parser.c b/src/tools/parser.c index 1f8a5220..d3a23264 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -156,7 +156,7 @@ parse_args(const char * const inp, int min, int max, gboolean *result) token = g_slist_next(token); int arg_count = 0; - while (token != NULL) { + while (token) { args[arg_count++] = strdup(token->data); token = g_slist_next(token); } @@ -303,7 +303,7 @@ parse_args_with_freetext(const char * const inp, int min, int max, gboolean *res token = g_slist_next(token); int arg_count = 0; - while (token != NULL) { + while (token) { args[arg_count++] = strdup(token->data); token = g_slist_next(token); } @@ -419,7 +419,7 @@ parse_options(gchar **args, gchar **opt_keys, gboolean *res) } // check if duplicate - if (g_list_find_custom(found_keys, args[curr], (GCompareFunc)g_strcmp0) != NULL) { + if (g_list_find_custom(found_keys, args[curr], (GCompareFunc)g_strcmp0)) { *res = FALSE; g_list_free(keys); return options; @@ -450,7 +450,7 @@ parse_options(gchar **args, gchar **opt_keys, gboolean *res) void options_destroy(GHashTable *options) { - if (options != NULL) { + if (options) { g_hash_table_destroy(options); } } From 09e1e7618e08a406dae31e55fddbd30975b4b354 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:57:49 +0100 Subject: [PATCH 12/35] Use null check convention in tinyurl.c --- src/tools/tinyurl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tinyurl.c b/src/tools/tinyurl.c index 34e8967a..92ff97b8 100644 --- a/src/tools/tinyurl.c +++ b/src/tools/tinyurl.c @@ -74,7 +74,7 @@ tinyurl_get(char *url) g_string_free(full_url, TRUE); - if (output.buffer != NULL) { + if (output.buffer) { output.buffer[output.size++] = '\0'; return output.buffer; } else { From 2e2b3f9403f1935447d1363873d6519db6c8d537 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:02:57 +0100 Subject: [PATCH 13/35] Use null check convention in console.c --- src/ui/console.c | 160 +++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 8dfd473f..a41ccad6 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -126,8 +126,8 @@ cons_show_typing(const char * const barejid) ProfWin *console = wins_get_console(); const char * display_usr = NULL; PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { display_usr = p_contact_name(contact); } else { display_usr = barejid; @@ -200,7 +200,7 @@ cons_check_version(gboolean not_available_msg) ProfWin *console = wins_get_console(); char *latest_release = release_get_latest(); - if (latest_release != NULL) { + if (latest_release) { gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); if (relase_valid) { @@ -247,7 +247,7 @@ cons_show_wins(void) GSList *window_strings = wins_create_summary(); GSList *curr = window_strings; - while (curr != NULL) { + while (curr) { win_println(console, curr->data); curr = g_slist_next(curr); } @@ -265,7 +265,7 @@ cons_show_room_invites(GSList *invites) cons_show("No outstanding chat room invites."); } else { cons_show("Chat room invites, use /join or /decline commands:"); - while (invites != NULL) { + while (invites) { cons_show(" %s", invites->data); invites = g_slist_next(invites); } @@ -298,48 +298,48 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_print(console, '-', NULL, NO_DATE, 0, "", ":"); // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(console, '-', NULL, NO_EOL, 0, "", "Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(console); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(console); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(console); } - if (caps->features != NULL) { + if (caps->features) { win_println(console, "Features:"); GSList *feature = caps->features; - while (feature != NULL) { + while (feature) { win_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data); feature = g_slist_next(feature); } @@ -358,19 +358,19 @@ cons_show_software_version(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) { ProfWin *console = wins_get_console(); - if ((name != NULL) || (version != NULL) || (os != NULL)) { + if (name || version || os) { cons_show(""); theme_item_t presence_colour = theme_main_presence_attrs(presence); win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid); win_print(console, '-', NULL, NO_DATE, 0, "", ":"); } - if (name != NULL) { + if (name) { cons_show("Name : %s", name); } - if (version != NULL) { + if (version) { cons_show("Version : %s", version); } - if (os != NULL) { + if (os) { cons_show("OS : %s", os); } @@ -386,7 +386,7 @@ cons_show_received_subs(void) } else { cons_show("Outstanding subscription requests from:", g_slist_length(received)); - while (received != NULL) { + while (received) { cons_show(" %s", received->data); received = g_slist_next(received); } @@ -404,7 +404,7 @@ cons_show_sent_subs(void) PContact contact = NULL; cons_show("Awaiting subscription responses from:"); GSList *curr = contacts; - while (curr != NULL) { + while (curr) { contact = (PContact) curr->data; if (p_contact_pending_out(contact)) { cons_show(" %s", p_contact_barejid(contact)); @@ -422,12 +422,12 @@ void cons_show_room_list(GSList *rooms, const char * const conference_node) { ProfWin *console = wins_get_console(); - if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { + if (rooms && (g_slist_length(rooms) > 0)) { cons_show("Chat rooms at %s:", conference_node); - while (rooms != NULL) { + while (rooms) { DiscoItem *room = rooms->data; win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid); - if (room->name != NULL) { + if (room->name) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); } win_newline(console); @@ -452,7 +452,7 @@ cons_show_bookmarks(const GList *list) cons_show(""); cons_show("Bookmarks:"); - while (list != NULL) { + while (list) { Bookmark *item = list->data; theme_item_t presence_colour = THEME_TEXT; @@ -461,18 +461,18 @@ cons_show_bookmarks(const GList *list) presence_colour = THEME_ONLINE; } win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid); - if (item->nick != NULL) { + if (item->nick) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); } if (item->autojoin) { win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); } - if (item->password != NULL) { + if (item->password) { win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)"); } if (muc_active(item->jid)) { ProfWin *roomwin = (ProfWin*)wins_get_muc(item->jid); - if (roomwin != NULL) { + if (roomwin) { int num = wins_get_num(roomwin); win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); } @@ -487,26 +487,26 @@ cons_show_bookmarks(const GList *list) void cons_show_disco_info(const char *jid, GSList *identities, GSList *features) { - if (((identities != NULL) && (g_slist_length(identities) > 0)) || - ((features != NULL) && (g_slist_length(features) > 0))) { + if ((identities && (g_slist_length(identities) > 0)) || + (features && (g_slist_length(features) > 0))) { cons_show(""); cons_show("Service disovery info for %s", jid); - if (identities != NULL) { + if (identities) { cons_show(" Identities"); } - while (identities != NULL) { + while (identities) { DiscoIdentity *identity = identities->data; // anme trpe, cat GString *identity_str = g_string_new(" "); - if (identity->name != NULL) { + if (identity->name) { identity_str = g_string_append(identity_str, identity->name); identity_str = g_string_append(identity_str, " "); } - if (identity->type != NULL) { + if (identity->type) { identity_str = g_string_append(identity_str, identity->type); identity_str = g_string_append(identity_str, " "); } - if (identity->category != NULL) { + if (identity->category) { identity_str = g_string_append(identity_str, identity->category); } cons_show(identity_str->str); @@ -514,10 +514,10 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features) identities = g_slist_next(identities); } - if (features != NULL) { + if (features) { cons_show(" Features:"); } - while (features != NULL) { + while (features) { cons_show(" %s", features->data); features = g_slist_next(features); } @@ -530,13 +530,13 @@ void cons_show_disco_items(GSList *items, const char * const jid) { ProfWin *console = wins_get_console(); - if ((items != NULL) && (g_slist_length(items) > 0)) { + if (items && (g_slist_length(items) > 0)) { cons_show(""); cons_show("Service discovery items for %s:", jid); - while (items != NULL) { + while (items) { DiscoItem *item = items->data; win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid); - if (item->name != NULL) { + if (item->name) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name); } win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); @@ -556,7 +556,7 @@ cons_show_status(const char * const barejid) ProfWin *console = wins_get_console(); PContact pcontact = roster_get_contact(barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_contact(console, pcontact); } else { cons_show("No such contact \"%s\" in roster.", barejid); @@ -571,8 +571,8 @@ cons_show_room_invite(const char * const invitor, const char * const room, { char *display_from = NULL; PContact contact = roster_get_contact(invitor); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { display_from = strdup(p_contact_name(contact)); } else { display_from = strdup(invitor); @@ -586,7 +586,7 @@ cons_show_room_invite(const char * const invitor, const char * const room, cons_show(" From : %s", display_from); cons_show(" Room : %s", room); - if (reason != NULL) { + if (reason) { cons_show(" Message: %s", reason); } @@ -673,9 +673,9 @@ cons_show_account(ProfAccount *account) if (g_list_length(account->otr_manual) > 0) { GString *manual = g_string_new("OTR manual : "); GList *curr = account->otr_manual; - while (curr != NULL) { + while (curr) { g_string_append(manual, curr->data); - if (curr->next != NULL) { + if (curr->next) { g_string_append(manual, ", "); } curr = curr->next; @@ -686,9 +686,9 @@ cons_show_account(ProfAccount *account) if (g_list_length(account->otr_opportunistic) > 0) { GString *opportunistic = g_string_new("OTR opportunistic : "); GList *curr = account->otr_opportunistic; - while (curr != NULL) { + while (curr) { g_string_append(opportunistic, curr->data); - if (curr->next != NULL) { + if (curr->next) { g_string_append(opportunistic, ", "); } curr = curr->next; @@ -699,9 +699,9 @@ cons_show_account(ProfAccount *account) if (g_list_length(account->otr_always) > 0) { GString *always = g_string_new("OTR always : "); GList *curr = account->otr_always; - while (curr != NULL) { + while (curr) { g_string_append(always, curr->data); - if (curr->next != NULL) { + if (curr->next) { g_string_append(always, ", "); } curr = curr->next; @@ -720,11 +720,11 @@ cons_show_account(ProfAccount *account) GList *ordered_resources = NULL; GList *curr = resources; - if (curr != NULL) { + if (curr) { win_println(console, "Resources:"); // sort in order of availability - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); @@ -735,13 +735,13 @@ cons_show_account(ProfAccount *account) g_list_free(resources); curr = ordered_resources; - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); - if (resource->status != NULL) { + if (resource->status) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); @@ -749,43 +749,43 @@ cons_show_account(ProfAccount *account) Capabilities *caps = caps_lookup(jidp->fulljid); jid_destroy(jidp); - if (caps != NULL) { + if (caps) { // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(console, '-', NULL, NO_EOL, 0, "", " Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(console); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(console); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(console); } caps_destroy(caps); @@ -808,10 +808,10 @@ cons_show_aliases(GList *aliases) } GList *curr = aliases; - if (curr != NULL) { + if (curr) { cons_show("Command aliases:"); } - while (curr != NULL) { + while (curr) { ProfAlias *alias = curr->data; cons_show(" /%s -> %s", alias->name, alias->value); curr = g_list_next(curr); @@ -919,7 +919,7 @@ void cons_autoconnect_setting(void) { char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT); - if (pref_connect_account != NULL) + if (pref_connect_account) cons_show("Autoconnect (/autoconnect) : %s", pref_connect_account); else cons_show("Autoconnect (/autoconnect) : OFF"); @@ -1412,7 +1412,7 @@ cons_show_themes(GSList *themes) cons_show("No available themes."); } else { cons_show("Available themes:"); - while (themes != NULL) { + while (themes) { cons_show(themes->data); themes = g_slist_next(themes); } @@ -1484,7 +1484,7 @@ cons_show_roster_group(const char * const group, GSList *list) { cons_show(""); - if (list != NULL) { + if (list) { cons_show("%s:", group); } else { cons_show("No group named %s exists.", group); @@ -1628,7 +1628,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) PContact contact = curr->data; GString *title = g_string_new(" "); title = g_string_append(title, p_contact_barejid(contact)); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { title = g_string_append(title, " ("); title = g_string_append(title, p_contact_name(contact)); title = g_string_append(title, ")"); @@ -1670,11 +1670,11 @@ _show_roster_contacts(GSList *list, gboolean show_groups) if (show_groups) { GSList *groups = p_contact_groups(contact); - if (groups != NULL) { + if (groups) { GString *groups_str = g_string_new(" - "); - while (groups != NULL) { + while (groups) { g_string_append(groups_str, groups->data); - if (g_slist_next(groups) != NULL) { + if (g_slist_next(groups)) { g_string_append(groups_str, ", "); } groups = g_slist_next(groups); From aefe458b600b72cc6d292aa177dde18b024ef1a3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:05:52 +0100 Subject: [PATCH 14/35] Use null check convention in core.c --- src/ui/core.c | 124 +++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index e75d5432..06dd84e3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -168,13 +168,13 @@ ui_get_idle_time(void) // if compiled with libxss, get the x sessions idle time #ifdef HAVE_LIBXSS XScreenSaverInfo *info = XScreenSaverAllocInfo(); - if (info != NULL && display != NULL) { + if (info && display) { XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); unsigned long result = info->idle; XFree(info); return result; } - if (info != NULL) { + if (info) { XFree(info); } // if no libxss or xss idle time failed, use profanity idle time @@ -352,7 +352,7 @@ ui_contact_typing(const char * const barejid, const char * const resource) if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) ) { PContact contact = roster_get_contact(barejid); char const *display_usr = NULL; - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { display_usr = p_contact_name(contact); } else { display_usr = barejid; @@ -423,9 +423,9 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c } // show users status first, when receiving message via delayed delivery - if ((tv_stamp != NULL) && (win_created)) { + if (tv_stamp && (win_created)) { PContact pcontact = roster_get_contact(barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_contact(window, pcontact); } } @@ -515,7 +515,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message, void ui_roster_add(const char * const barejid, const char * const name) { - if (name != NULL) { + if (name) { cons_show("Roster item added: %s (%s)", barejid, name); } else { cons_show("Roster item added: %s", barejid); @@ -562,7 +562,7 @@ void ui_auto_away(void) { char *pref_autoaway_message = prefs_get_string(PREF_AUTOAWAY_MESSAGE); - if (pref_autoaway_message != NULL) { + if (pref_autoaway_message) { int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), RESOURCE_AWAY); @@ -618,7 +618,7 @@ ui_update_presence(const resource_presence_t resource_presence, contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); title_bar_set_presence(contact_presence); gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), resource_presence); - if (message != NULL) { + if (message) { cons_show("Status set to %s (priority %d), \"%s\".", show, priority, message); } else { cons_show("Status set to %s (priority %d).", show, priority); @@ -676,7 +676,7 @@ ui_handle_error(const char * const err_msg) void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) { - if (setting_func != NULL) { + if (setting_func) { cons_show(""); (*setting_func)(); cons_show("Usage: %s", usage); @@ -733,7 +733,7 @@ ui_close_all_wins(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); if ((num != 1) && (!ui_win_has_unsaved_form(num))) { if (conn_status == JABBER_CONNECTED) { @@ -760,7 +760,7 @@ ui_close_read_wins(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); if ((num != 1) && (ui_win_unread(num) == 0) && (!ui_win_has_unsaved_form(num))) { if (conn_status == JABBER_CONNECTED) { @@ -784,7 +784,7 @@ ui_redraw_all_room_rosters(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); ProfWin *window = wins_get_by_num(num); if (window->type == WIN_MUC && win_has_active_subwin(window)) { @@ -805,7 +805,7 @@ ui_hide_all_room_rosters(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); ProfWin *window = wins_get_by_num(num); if (window->type == WIN_MUC && win_has_active_subwin(window)) { @@ -826,7 +826,7 @@ ui_show_all_room_rosters(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); ProfWin *window = wins_get_by_num(num); if (window->type == WIN_MUC && !win_has_active_subwin(window)) { @@ -1112,12 +1112,12 @@ ui_prune_wins(void) gboolean pruned = FALSE; GSList *wins = wins_get_prune_wins(); - if (wins != NULL) { + if (wins) { pruned = TRUE; } GSList *curr = wins; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_CHAT) { if (conn_status == JABBER_CONNECTED) { @@ -1132,7 +1132,7 @@ ui_prune_wins(void) curr = g_slist_next(curr); } - if (wins != NULL) { + if (wins) { g_slist_free(wins); } @@ -1226,7 +1226,7 @@ ui_print_system_msg_from_recipient(const char * const barejid, const char *messa if (window == NULL) { int num = 0; window = wins_new_chat(barejid); - if (window != NULL) { + if (window) { num = wins_get_num(window); status_bar_active(num); } else { @@ -1258,8 +1258,8 @@ ui_recipient_gone(const char * const barejid, const char * const resource) if (show_message) { const char * display_usr = NULL; PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { display_usr = p_contact_name(contact); } else { display_usr = barejid; @@ -1506,23 +1506,23 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - if (((identities != NULL) && (g_slist_length(identities) > 0)) || - ((features != NULL) && (g_slist_length(features) > 0))) { - if (identities != NULL) { + if ((identities && (g_slist_length(identities) > 0)) || + (features && (g_slist_length(features) > 0))) { + if (identities) { win_print(window, '!', NULL, 0, 0, "", "Identities:"); } - while (identities != NULL) { + while (identities) { DiscoIdentity *identity = identities->data; // anme trpe, cat GString *identity_str = g_string_new(" "); - if (identity->name != NULL) { + if (identity->name) { identity_str = g_string_append(identity_str, identity->name); identity_str = g_string_append(identity_str, " "); } - if (identity->type != NULL) { + if (identity->type) { identity_str = g_string_append(identity_str, identity->type); identity_str = g_string_append(identity_str, " "); } - if (identity->category != NULL) { + if (identity->category) { identity_str = g_string_append(identity_str, identity->category); } win_print(window, '!', NULL, 0, 0, "", identity_str->str); @@ -1530,10 +1530,10 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * identities = g_slist_next(identities); } - if (features != NULL) { + if (features) { win_print(window, '!', NULL, 0, 0, "", "Features:"); } - while (features != NULL) { + while (features) { win_vprint(window, '!', NULL, 0, 0, "", " %s", features->data); features = g_slist_next(features); } @@ -1563,14 +1563,14 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); } - while (roster != NULL) { + while (roster) { Occupant *occupant = roster->data; const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); - if (roster->next != NULL) { + if (roster->next) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", "); } @@ -1742,7 +1742,7 @@ ui_room_message(const char * const roomjid, const char * const nick, char *my_nick = muc_nick(roomjid); if (g_strcmp0(nick, my_nick) != 0) { - if (g_strrstr(message, my_nick) != NULL) { + if (g_strrstr(message, my_nick)) { win_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); } else { win_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); @@ -1787,7 +1787,7 @@ ui_room_message(const char * const roomjid, const char * const nick, if (g_strcmp0(room_setting, "mention") == 0) { char *message_lower = g_utf8_strdown(message, -1); char *nick_lower = g_utf8_strdown(nick, -1); - if (g_strrstr(message_lower, nick_lower) != NULL) { + if (g_strrstr(message_lower, nick_lower)) { notify = TRUE; } g_free(message_lower); @@ -2121,7 +2121,7 @@ int ui_win_unread(int index) { ProfWin *window = wins_get_by_num(index); - if (window != NULL) { + if (window) { return win_unread(window); } else { return 0; @@ -2144,7 +2144,7 @@ ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last const char *barejid = p_contact_barejid(contact); ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window != NULL) { + if (window) { win_show_status_string(window, display_str, show, resource->status, last_activity, "++", "online"); @@ -2160,7 +2160,7 @@ ui_chat_win_contact_offline(PContact contact, char *resource, char *status) const char *barejid = p_contact_barejid(contact); ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window != NULL) { + if (window) { win_show_status_string(window, display_str, "offline", status, NULL, "--", "offline"); } @@ -2175,7 +2175,7 @@ ui_contact_offline(char *barejid, char *resource, char *status) char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); Jid *jid = jid_create_from_bare_and_resource(barejid, resource); PContact contact = roster_get_contact(barejid); - if (p_contact_subscription(contact) != NULL) { + if (p_contact_subscription(contact)) { if (strcmp(p_contact_subscription(contact), "none") != 0) { // show in console if "all" @@ -2256,7 +2256,7 @@ _ui_draw_term_title(void) if (res == -1) { log_error("Error writing terminal window title."); } - if (win_title != NULL) { + if (win_title) { free(win_title); } win_title = strdup(new_win_title); @@ -2408,9 +2408,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) case FIELD_HIDDEN: break; case FIELD_TEXT_SINGLE: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { if (g_strcmp0(field->var, "muc#roomconfig_roomsecret") == 0) { win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } else { @@ -2421,9 +2421,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_newline(window); break; case FIELD_TEXT_PRIVATE: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } } @@ -2432,7 +2432,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) case FIELD_TEXT_MULTI: win_newline(window); int index = 1; - while (curr_value != NULL) { + while (curr_value) { char *value = curr_value->data; GString *val_tag = g_string_new(""); g_string_printf(val_tag, "val%d", index++); @@ -2458,12 +2458,12 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } break; case FIELD_LIST_SINGLE: - if (curr_value != NULL) { + if (curr_value) { win_newline(window); char *value = curr_value->data; GSList *options = field->options; GSList *curr_option = options; - while (curr_option != NULL) { + while (curr_option) { FormOption *option = curr_option->data; if (g_strcmp0(option->value, value) == 0) { win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); @@ -2475,13 +2475,13 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } break; case FIELD_LIST_MULTI: - if (curr_value != NULL) { + if (curr_value) { win_newline(window); GSList *options = field->options; GSList *curr_option = options; - while (curr_option != NULL) { + while (curr_option) { FormOption *option = curr_option->data; - if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0) != NULL) { + if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) { win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); } else { win_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); @@ -2491,9 +2491,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } break; case FIELD_JID_SINGLE: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } @@ -2501,16 +2501,16 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) break; case FIELD_JID_MULTI: win_newline(window); - while (curr_value != NULL) { + while (curr_value) { char *value = curr_value->data; win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " %s", value); curr_value = g_slist_next(curr_value); } break; case FIELD_FIXED: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", value); } } @@ -2525,7 +2525,7 @@ void ui_show_form(ProfMucConfWin *confwin) { ProfWin *window = (ProfWin*) confwin; - if (confwin->form->title != NULL) { + if (confwin->form->title) { win_print(window, '-', NULL, NO_EOL, 0, "", "Form title: "); win_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title); } else { @@ -2537,7 +2537,7 @@ ui_show_form(ProfMucConfWin *confwin) GSList *fields = confwin->form->fields; GSList *curr_field = fields; - while (curr_field != NULL) { + while (curr_field) { FormField *field = curr_field->data; if ((g_strcmp0(field->type, "fixed") == 0) && field->values) { @@ -2680,14 +2680,14 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) { ProfWin *window = (ProfWin*) confwin; FormField *field = form_get_field_by_tag(confwin->form, tag); - if (field != NULL) { + if (field) { win_print(window, '-', NULL, NO_EOL, 0, "", field->label); if (field->required) { win_print(window, '-', NULL, NO_DATE, 0, "", " (Required):"); } else { win_print(window, '-', NULL, NO_DATE, 0, "", ":"); } - if (field->description != NULL) { + if (field->description) { win_vprint(window, '-', NULL, 0, 0, "", " Description : %s", field->description); } win_vprint(window, '-', NULL, 0, 0, "", " Type : %s", field->type); @@ -2719,7 +2719,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; - while (curr_option != NULL) { + while (curr_option) { option = curr_option->data; win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); @@ -2730,7 +2730,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; - while (curr_option != NULL) { + while (curr_option) { option = curr_option->data; win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); @@ -2759,7 +2759,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) void ui_show_form_help(ProfMucConfWin *confwin) { - if (confwin->form->instructions != NULL) { + if (confwin->form->instructions) { ProfWin *window = (ProfWin*) confwin; win_print(window, '-', NULL, 0, 0, "", "Supplied instructions:"); win_print(window, '-', NULL, 0, 0, "", confwin->form->instructions); @@ -2770,7 +2770,7 @@ ui_show_form_help(ProfMucConfWin *confwin) void ui_show_lines(ProfWin *window, const gchar** lines) { - if (lines != NULL) { + if (lines) { int i; for (i = 0; lines[i] != NULL; i++) { win_print(window, '-', NULL, 0, 0, "", lines[i]); @@ -2833,7 +2833,7 @@ _win_show_history(ProfChatWin *chatwin, const char * const contact) GSList *history = chat_log_get_previous(jid->barejid, contact); jid_destroy(jid); GSList *curr = history; - while (curr != NULL) { + while (curr) { char *line = curr->data; // entry if (line[2] == ':') { From dda812cd3efbf4029ece7705f4d912ce6d52ea90 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:06:35 +0100 Subject: [PATCH 15/35] Use null check convention in notifier.c --- src/ui/notifier.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/notifier.c b/src/ui/notifier.c index e8bc61e3..d3389bc5 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -89,7 +89,7 @@ notify_invite(const char * const from, const char * const room, g_string_append(message, from); g_string_append(message, "\nto: "); g_string_append(message, room); - if (reason != NULL) { + if (reason) { g_string_append_printf(message, "\n\"%s\"", reason); } @@ -103,7 +103,7 @@ notify_message(const char * const handle, int win, const char * const text) { GString *message = g_string_new(""); g_string_append_printf(message, "%s (win %d)", handle, win); - if (text != NULL) { + if (text) { g_string_append_printf(message, "\n%s", text); } @@ -117,7 +117,7 @@ notify_room_message(const char * const handle, const char * const room, int win, { GString *message = g_string_new(""); g_string_append_printf(message, "%s in %s (win %d)", handle, room, win); - if (text != NULL) { + if (text) { g_string_append_printf(message, "\n%s", text); } @@ -274,7 +274,7 @@ _notify(const char * const message, int timeout, app_id = "com.googlecode.iterm2"; } - if (app_id != NULL) { + if (app_id) { g_string_append(notify_command, " -sender "); g_string_append(notify_command, app_id); } From bf5646aee31864945c767eeb676c0de84756051a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:07:36 +0100 Subject: [PATCH 16/35] Use null check convention in statusbar.c --- src/ui/statusbar.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 93eeaab0..581e63df 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -95,7 +95,7 @@ create_status_bar(void) mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); - if (last_time != NULL) { + if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); @@ -127,7 +127,7 @@ status_bar_resize(void) mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); - if (message != NULL) { + if (message) { char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(time_pref, "minutes") == 0) { mvwprintw(status_bar, 0, 10, message); @@ -137,7 +137,7 @@ status_bar_resize(void) mvwprintw(status_bar, 0, 1, message); } } - if (last_time != NULL) { + if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); @@ -297,7 +297,7 @@ status_bar_print_message(const char * const msg) { werase(status_bar); - if (message != NULL) { + if (message) { free(message); } message = strdup(msg); @@ -325,7 +325,7 @@ status_bar_print_message(const char * const msg) void status_bar_clear(void) { - if (message != NULL) { + if (message) { free(message); message = NULL; } @@ -346,7 +346,7 @@ status_bar_clear(void) void status_bar_clear_message(void) { - if (message != NULL) { + if (message) { free(message); message = NULL; } @@ -428,7 +428,7 @@ _mark_inactive(int num) static void _status_bar_draw(void) { - if (last_time != NULL) { + if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); From dd386b4a4ed6cb732bd4aaf88131748d3697b441 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:08:09 +0100 Subject: [PATCH 17/35] Use null check convention in titlebar.c --- src/ui/titlebar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 08c9a8e6..9bb84f9d 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -80,7 +80,7 @@ title_bar_update_virtual(void) { ProfWin *window = wins_get_current(); if (window->type != WIN_CONSOLE) { - if (typing_elapsed != NULL) { + if (typing_elapsed) { gdouble seconds = g_timer_elapsed(typing_elapsed, NULL); if (seconds >= 10) { @@ -128,7 +128,7 @@ title_bar_set_presence(contact_presence_t presence) void title_bar_switch(void) { - if (typing_elapsed != NULL) { + if (typing_elapsed) { g_timer_destroy(typing_elapsed); typing_elapsed = NULL; typing = FALSE; @@ -141,7 +141,7 @@ void title_bar_set_typing(gboolean is_typing) { if (is_typing) { - if (typing_elapsed != NULL) { + if (typing_elapsed) { g_timer_start(typing_elapsed); } else { typing_elapsed = g_timer_new(); From c19a05ca0943477bf600b91e644526810492b477 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:11:32 +0100 Subject: [PATCH 18/35] Use null check convention in window.c --- src/ui/window.c | 76 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 60c71802..9752ffda 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -573,7 +573,7 @@ win_show_contact(ProfWin *window, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); - if (name != NULL) { + if (name) { win_print(window, '-', NULL, NO_EOL, presence_colour, "", name); } else { win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); @@ -581,7 +581,7 @@ win_show_contact(ProfWin *window, PContact contact) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); - if (last_activity != NULL) { + if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); @@ -599,7 +599,7 @@ win_show_contact(ProfWin *window, PContact contact) } } - if (status != NULL) { + if (status) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } @@ -637,41 +637,41 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup if (caps) { // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(window); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(window); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(window); } caps_destroy(caps); @@ -693,16 +693,16 @@ win_show_info(ProfWin *window, PContact contact) win_print(window, '-', NULL, 0, 0, "", ""); win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); - if (name != NULL) { + if (name) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); } win_print(window, '-', NULL, NO_DATE, 0, "", ":"); - if (sub != NULL) { + if (sub) { win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); } - if (last_activity != NULL) { + if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); @@ -724,12 +724,12 @@ win_show_info(ProfWin *window, PContact contact) GList *resources = p_contact_get_available_resources(contact); GList *ordered_resources = NULL; - if (resources != NULL) { + if (resources) { win_print(window, '-', NULL, 0, 0, "", "Resources:"); // sort in order of availability GList *curr = resources; - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); @@ -739,12 +739,12 @@ win_show_info(ProfWin *window, PContact contact) g_list_free(resources); GList *curr = ordered_resources; - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); - if (resource->status != NULL) { + if (resource->status) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_newline(window); @@ -755,41 +755,41 @@ win_show_info(ProfWin *window, PContact contact) if (caps) { // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(window); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(window); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(window); } caps_destroy(caps); @@ -808,7 +808,7 @@ win_show_status_string(ProfWin *window, const char * const from, { theme_item_t presence_colour; - if (show != NULL) { + if (show) { presence_colour = theme_main_presence_attrs(show); } else if (strcmp(default_show, "online") == 0) { presence_colour = THEME_ONLINE; @@ -819,12 +819,12 @@ win_show_status_string(ProfWin *window, const char * const from, win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); - if (show != NULL) + if (show) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); else win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); - if (last_activity != NULL) { + if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); g_date_time_unref(now); @@ -843,7 +843,7 @@ win_show_status_string(ProfWin *window, const char * const from, } } - if (status != NULL) + if (status) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); From a71d1dab6a6a8b4bb16363d3b59d126e6e7988f7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:12:55 +0100 Subject: [PATCH 19/35] Use null check convention in windows.c --- src/ui/windows.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ui/windows.c b/src/ui/windows.c index 7a86403b..2334efc8 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -84,7 +84,7 @@ wins_get_chat(const char * const barejid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)window; @@ -106,7 +106,7 @@ wins_get_muc_conf(const char * const roomjid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_MUC_CONFIG) { ProfMucConfWin *confwin = (ProfMucConfWin*)window; @@ -128,7 +128,7 @@ wins_get_muc(const char * const roomjid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*)window; @@ -150,7 +150,7 @@ wins_get_private(const char * const fulljid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_PRIVATE) { ProfPrivateWin *privatewin = (ProfPrivateWin*)window; @@ -169,7 +169,7 @@ wins_get_private(const char * const fulljid) ProfWin * wins_get_current(void) { - if (windows != NULL) { + if (windows) { return g_hash_table_lookup(windows, GINT_TO_POINTER(current)); } else { return NULL; @@ -286,7 +286,7 @@ wins_get_next(void) GList *curr = keys; // find our place in the list - while (curr != NULL) { + while (curr) { if (current == GPOINTER_TO_INT(curr->data)) { break; } @@ -295,7 +295,7 @@ wins_get_next(void) // if there is a next window return it curr = g_list_next(curr); - if (curr != NULL) { + if (curr) { int next = GPOINTER_TO_INT(curr->data); g_list_free(keys); return wins_get_by_num(next); @@ -315,7 +315,7 @@ wins_get_previous(void) GList *curr = keys; // find our place in the list - while (curr != NULL) { + while (curr) { if (current == GPOINTER_TO_INT(curr->data)) { break; } @@ -324,7 +324,7 @@ wins_get_previous(void) // if there is a previous window return it curr = g_list_previous(curr); - if (curr != NULL) { + if (curr) { int previous = GPOINTER_TO_INT(curr->data); g_list_free(keys); return wins_get_by_num(previous); @@ -342,7 +342,7 @@ wins_get_num(ProfWin *window) GList *keys = g_hash_table_get_keys(windows); GList *curr = keys; - while (curr != NULL) { + while (curr) { gconstpointer num_p = curr->data; ProfWin *curr_win = g_hash_table_lookup(windows, num_p); if (curr_win == window) { @@ -468,7 +468,7 @@ wins_get_total_unread(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; result += win_unread(window); curr = g_list_next(curr); @@ -484,7 +484,7 @@ wins_resize_all(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; int subwin_cols = 0; @@ -564,7 +564,7 @@ wins_get_xmlconsole(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_XML) { ProfXMLWin *xmlwin = (ProfXMLWin*)window; @@ -586,7 +586,7 @@ wins_get_chat_recipients(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)window; @@ -605,7 +605,7 @@ wins_get_prune_wins(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (win_unread(window) == 0 && window->type != WIN_MUC && @@ -626,7 +626,7 @@ wins_lost_connection(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type != WIN_CONSOLE) { win_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection."); @@ -719,7 +719,7 @@ wins_tidy(void) int num = 1; GList *curr = keys; - while (curr != NULL) { + while (curr) { ProfWin *window = g_hash_table_lookup(windows, curr->data); if (num == 10) { g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window); @@ -761,7 +761,7 @@ wins_create_summary(void) keys = g_list_sort(keys, cmp_win_num); GList *curr = keys; - while (curr != NULL) { + while (curr) { ProfWin *window = g_hash_table_lookup(windows, curr->data); int ui_index = GPOINTER_TO_INT(curr->data); From 398eac4ed6d204cbf8b059a00c08b9ca121cf544 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:14:18 +0100 Subject: [PATCH 20/35] Use null check convention in bookmark.c --- src/xmpp/bookmark.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 9e7bf62b..68e66569 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -74,7 +74,7 @@ bookmark_request(void) autocomplete_free(bookmark_ac); bookmark_ac = autocomplete_new(); - if (bookmark_list != NULL) { + if (bookmark_list) { g_list_free_full(bookmark_list, _bookmark_item_destroy); bookmark_list = NULL; } @@ -96,12 +96,12 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char } else { Bookmark *item = malloc(sizeof(*item)); item->jid = strdup(jid); - if (nick != NULL) { + if (nick) { item->nick = strdup(nick); } else { item->nick = NULL; } - if (password != NULL) { + if (password) { item->password = strdup(password); } else { item->password = NULL; @@ -136,15 +136,15 @@ bookmark_update(const char *jid, const char *nick, const char *password, const c return FALSE; } else { Bookmark *bm = found->data; - if (nick != NULL) { + if (nick) { free(bm->nick); bm->nick = strdup(nick); } - if (password != NULL) { + if (password) { free(bm->password); bm->password = strdup(password); } - if (autojoin_str != NULL) { + if (autojoin_str) { if (g_strcmp0(autojoin_str, "on") == 0) { bm->autojoin = TRUE; } else if (g_strcmp0(autojoin_str, "off") == 0) { @@ -228,7 +228,7 @@ bookmark_find(const char * const search_str) void bookmark_autocomplete_reset(void) { - if (bookmark_ac != NULL) { + if (bookmark_ac) { autocomplete_reset(bookmark_ac); } } @@ -413,14 +413,14 @@ _send_bookmarks(void) xmpp_stanza_set_ns(storage, "storage:bookmarks"); GList *curr = bookmark_list; - while (curr != NULL) { + while (curr) { Bookmark *bookmark = curr->data; xmpp_stanza_t *conference = xmpp_stanza_new(ctx); xmpp_stanza_set_name(conference, STANZA_NAME_CONFERENCE); xmpp_stanza_set_attribute(conference, STANZA_ATTR_JID, bookmark->jid); Jid *jidp = jid_create(bookmark->jid); - if (jidp->localpart != NULL) { + if (jidp->localpart) { xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, jidp->localpart); } jid_destroy(jidp); @@ -431,7 +431,7 @@ _send_bookmarks(void) xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "false"); } - if (bookmark->nick != NULL) { + if (bookmark->nick) { xmpp_stanza_t *nick_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(nick_st, STANZA_NAME_NICK); xmpp_stanza_t *nick_text = xmpp_stanza_new(ctx); @@ -443,7 +443,7 @@ _send_bookmarks(void) xmpp_stanza_release(nick_st); } - if (bookmark->password != NULL) { + if (bookmark->password) { xmpp_stanza_t *password_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(password_st, STANZA_NAME_PASSWORD); xmpp_stanza_t *password_text = xmpp_stanza_new(ctx); From 067ad7fa2cb4354531c2bc9b51c97af48c17d92f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:15:15 +0100 Subject: [PATCH 21/35] Use null check convention in capabilities.c --- src/xmpp/capabilities.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 54144330..56475da1 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -203,7 +203,7 @@ _caps_by_ver(const char * const ver) gsize features_len = 0; gchar **features = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL); - if (features != NULL && features_len > 0) { + if (features && features_len > 0) { GSList *features_list = NULL; int i; for (i = 0; i < features_len; i++) { @@ -395,16 +395,16 @@ caps_create(xmpp_stanza_t *query) GSList *features = NULL; xmpp_stanza_t *softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); - if (softwareinfo != NULL) { + if (softwareinfo) { DataForm *form = form_create(softwareinfo); FormField *formField = NULL; char *form_type = form_get_form_type_field(form); if (g_strcmp0(form_type, STANZA_DATAFORM_SOFTWARE) == 0) { GSList *field = form->fields; - while (field != NULL) { + while (field) { formField = field->data; - if (formField->values != NULL) { + if (formField->values) { if (strcmp(formField->var, "software") == 0) { software = strdup(formField->values->data); } else if (strcmp(formField->var, "software_version") == 0) { @@ -424,7 +424,7 @@ caps_create(xmpp_stanza_t *query) xmpp_stanza_t *child = xmpp_stanza_get_children(query); GSList *identity_stanzas = NULL; - while (child != NULL) { + while (child) { if (g_strcmp0(xmpp_stanza_get_name(child), "feature") == 0) { features = g_slist_append(features, strdup(xmpp_stanza_get_attribute(child, "var"))); } @@ -490,42 +490,42 @@ caps_create(xmpp_stanza_t *query) Capabilities *new_caps = malloc(sizeof(struct capabilities_t)); - if (category != NULL) { + if (category) { new_caps->category = strdup(category); } else { new_caps->category = NULL; } - if (type != NULL) { + if (type) { new_caps->type = strdup(type); } else { new_caps->type = NULL; } - if (name != NULL) { + if (name) { new_caps->name = strdup(name); } else { new_caps->name = NULL; } - if (software != NULL) { + if (software) { new_caps->software = software; } else { new_caps->software = NULL; } - if (software_version != NULL) { + if (software_version) { new_caps->software_version = software_version; } else { new_caps->software_version = NULL; } - if (os != NULL) { + if (os) { new_caps->os = os; } else { new_caps->os = NULL; } - if (os_version != NULL) { + if (os_version) { new_caps->os_version = os_version; } else { new_caps->os_version = NULL; } - if (features != NULL) { + if (features) { new_caps->features = features; } else { new_caps->features = NULL; @@ -635,7 +635,7 @@ caps_close(void) void caps_destroy(Capabilities *caps) { - if (caps != NULL) { + if (caps) { free(caps->category); free(caps->type); free(caps->name); @@ -643,7 +643,7 @@ caps_destroy(Capabilities *caps) free(caps->software_version); free(caps->os); free(caps->os_version); - if (caps->features != NULL) { + if (caps->features) { g_slist_free_full(caps->features, free); } free(caps); From af75bc4be67422b7523707ec56db4a9cde59429b Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:16:44 +0100 Subject: [PATCH 22/35] Use null check convention in connection.c --- src/xmpp/connection.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index f2596f14..70d49b7c 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -129,11 +129,11 @@ jabber_connect_with_account(const ProfAccount * const account) log_info("Connecting using account: %s", account->name); // save account name and password for reconnect - if (saved_account.name != NULL) { + if (saved_account.name) { free(saved_account.name); } saved_account.name = strdup(account->name); - if (saved_account.passwd != NULL) { + if (saved_account.passwd) { free(saved_account.passwd); } saved_account.passwd = strdup(account->password); @@ -157,7 +157,7 @@ jabber_connect_with_details(const char * const jid, // save details for reconnect, remember name for account creating on success saved_details.name = strdup(jid); saved_details.passwd = strdup(passwd); - if (altdomain != NULL) { + if (altdomain) { saved_details.altdomain = strdup(altdomain); } else { saved_details.altdomain = NULL; @@ -199,11 +199,11 @@ jabber_disconnect(void) _connection_free_saved_account(); _connection_free_saved_details(); _connection_free_session_data(); - if (jabber_conn.conn != NULL) { + if (jabber_conn.conn) { xmpp_conn_release(jabber_conn.conn); jabber_conn.conn = NULL; } - if (jabber_conn.ctx != NULL) { + if (jabber_conn.ctx) { xmpp_ctx_free(jabber_conn.ctx); jabber_conn.ctx = NULL; } @@ -238,7 +238,7 @@ jabber_process_events(void) break; case JABBER_DISCONNECTED: reconnect_sec = prefs_get_reconnect(); - if ((reconnect_sec != 0) && (reconnect_timer != NULL)) { + if ((reconnect_sec != 0) && reconnect_timer) { int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL); if (elapsed_sec > reconnect_sec) { _jabber_reconnect(); @@ -302,7 +302,7 @@ void connection_set_presence_message(const char * const message) { FREE_SET_NULL(jabber_conn.presence_message); - if (message != NULL) { + if (message) { jabber_conn.presence_message = strdup(message); } } @@ -371,15 +371,15 @@ _jabber_connect(const char * const fulljid, const char * const passwd, jid_destroy(jid); log_info("Connecting as %s", fulljid); - if (jabber_conn.log != NULL) { + if (jabber_conn.log) { free(jabber_conn.log); } jabber_conn.log = _xmpp_get_file_logger(); - if (jabber_conn.conn != NULL) { + if (jabber_conn.conn) { xmpp_conn_release(jabber_conn.conn); } - if (jabber_conn.ctx != NULL) { + if (jabber_conn.ctx) { xmpp_ctx_free(jabber_conn.ctx); } jabber_conn.ctx = xmpp_ctx_new(NULL, jabber_conn.log); @@ -436,7 +436,7 @@ _connection_handler(xmpp_conn_t * const conn, log_debug("Connection handler: XMPP_CONN_CONNECT"); // logged in with account - if (saved_account.name != NULL) { + if (saved_account.name) { log_debug("Connection handler: logged in with account name: %s", saved_account.name); sv_ev_login_account_success(saved_account.name); @@ -474,7 +474,7 @@ _connection_handler(xmpp_conn_t * const conn, jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { - if (reconnect_timer != NULL) { + if (reconnect_timer) { g_timer_destroy(reconnect_timer); reconnect_timer = NULL; } From cbcf476a7c63642d0b520460eb94064dd27b4b97 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:17:18 +0100 Subject: [PATCH 23/35] Use null check convention in form.c --- src/xmpp/form.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/form.c b/src/xmpp/form.c index 02d26ba0..e6213b64 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -211,7 +211,7 @@ form_create(xmpp_stanza_t * const form_stanza) field->var = _get_attr(field_stanza, "var"); - if (field->type_t != FIELD_HIDDEN && field->var != NULL) { + if (field->type_t != FIELD_HIDDEN && field->var) { GString *tag = g_string_new(""); g_string_printf(tag, "field%d", tag_num++); g_hash_table_insert(form->var_to_tag, strdup(field->var), strdup(tag->str)); From 8e2578459e29a26b53cb05df2305052c6f8064b0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:19:10 +0100 Subject: [PATCH 24/35] Use null check convention in iq.c --- src/xmpp/iq.c | 96 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 1a0f64a9..18abad36 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -476,7 +476,7 @@ _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); char *error_msg = stanza_get_error_message(stanza); - if (id != NULL) { + if (id) { log_debug("IQ error handler fired, id: %s, error: %s", id, error_msg); log_error("IQ error received, id: %s, error: %s", id, error_msg); } else { @@ -496,13 +496,13 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, char *id = xmpp_stanza_get_id(stanza); char *type = xmpp_stanza_get_type(stanza); - if (id != NULL) { + if (id) { log_debug("IQ pong handler fired, id: %s.", id); } else { log_debug("IQ pong handler fired."); } - if (id != NULL && type != NULL) { + if (id && type) { // show warning if error if (strcmp(type, STANZA_TYPE_ERROR) == 0) { char *error_msg = stanza_get_error_message(stanza); @@ -511,9 +511,9 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, // turn off autoping if error type is 'cancel' xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); - if (error != NULL) { + if (error) { char *errtype = xmpp_stanza_get_type(error); - if (errtype != NULL) { + if (errtype) { if (strcmp(errtype, "cancel") == 0) { log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); prefs_set_autoping(0); @@ -830,7 +830,7 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { char *id = xmpp_stanza_get_id(stanza); - if (id != NULL) { + if (id) { log_debug("IQ version result handler fired, id: %s.", id); } else { log_debug("IQ version result handler fired."); @@ -855,13 +855,13 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version"); xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os"); - if (name != NULL) { + if (name) { name_str = xmpp_stanza_get_text(name); } - if (version != NULL) { + if (version) { version_str = xmpp_stanza_get_text(version); } - if (os != NULL) { + if (os) { os_str = xmpp_stanza_get_text(os); } @@ -892,7 +892,7 @@ _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *to = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TO); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ ping get handler fired, id: %s.", id); } else { log_debug("IQ ping get handler fired."); @@ -908,7 +908,7 @@ _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_set_attribute(pong, STANZA_ATTR_FROM, to); xmpp_stanza_set_attribute(pong, STANZA_ATTR_TYPE, STANZA_TYPE_RESULT); - if (id != NULL) { + if (id) { xmpp_stanza_set_attribute(pong, STANZA_ATTR_ID, id); } @@ -926,16 +926,16 @@ _version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ version get handler fired, id: %s.", id); } else { log_debug("IQ version get handler fired."); } - if (from != NULL) { + if (from) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); - if (id != NULL) { + if (id) { xmpp_stanza_set_id(response, id); } xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); @@ -994,13 +994,13 @@ _disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ disco items get handler fired, id: %s.", id); } else { log_debug("IQ disco items get handler fired."); } - if (from != NULL) { + if (from) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); @@ -1031,20 +1031,20 @@ _disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - if (id != NULL) { + if (id) { log_debug("IQ disco info get handler fired, id: %s.", id); } else { log_debug("IQ disco info get handler fired."); } - if (from != NULL) { + if (from) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); xmpp_stanza_t *query = caps_create_query_response_stanza(ctx); - if (node_str != NULL) { + if (node_str) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str); } xmpp_stanza_add_child(response, query); @@ -1063,7 +1063,7 @@ _destroy_room_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - if (id != NULL) { + if (id) { log_debug("IQ destroy room result handler fired, id: %s.", id); } else { log_debug("IQ destroy room result handler fired."); @@ -1087,7 +1087,7 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *type = xmpp_stanza_get_type(stanza); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ room config handler fired, id: %s.", id); } else { log_debug("IQ room config handler fired."); @@ -1142,7 +1142,7 @@ static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, xmpp_s const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); struct privilege_set_t *affiliation_set = (struct privilege_set_t *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ affiliation set handler fired, id: %s.", id); } else { log_debug("IQ affiliation set handler fired."); @@ -1171,7 +1171,7 @@ static int _room_role_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); struct privilege_set_t *role_set = (struct privilege_set_t *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ role set handler fired, id: %s.", id); } else { log_debug("IQ role set handler fired."); @@ -1200,7 +1200,7 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *affiliation = (char *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ affiliation list result handler fired, id: %s.", id); } else { log_debug("IQ affiliation list result handler fired."); @@ -1248,7 +1248,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *role = (char *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ role list result handler fired, id: %s.", id); } else { log_debug("IQ role list result handler fired."); @@ -1295,7 +1295,7 @@ _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan const char *type = xmpp_stanza_get_type(stanza); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ room config submit handler fired, id: %s.", id); } else { log_debug("IQ room config submit handler fired."); @@ -1322,7 +1322,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *nick = (char *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ kick result handler fired, id: %s.", id); } else { log_debug("IQ kick result handler fired."); @@ -1345,7 +1345,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza static void _identity_destroy(DiscoIdentity *identity) { - if (identity != NULL) { + if (identity) { free(identity->name); free(identity->type); free(identity->category); @@ -1356,7 +1356,7 @@ _identity_destroy(DiscoIdentity *identity) static void _item_destroy(DiscoItem *item) { - if (item != NULL) { + if (item) { free(item->jid); free(item->name); free(item); @@ -1385,15 +1385,15 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - if (query != NULL) { + if (query) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); GSList *identities = NULL; GSList *features = NULL; - while (child != NULL) { + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) { const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR); - if (var != NULL) { + if (var) { features = g_slist_append(features, strdup(var)); } } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { @@ -1401,20 +1401,20 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); - if ((name != NULL) || (category != NULL) || (type != NULL)) { + if (name || category || type) { DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t)); - if (name != NULL) { + if (name) { identity->name = strdup(name); } else { identity->name = NULL; } - if (category != NULL) { + if (category) { identity->category = strdup(category); } else { identity->category = NULL; } - if (type != NULL) { + if (type) { identity->type = strdup(type); } else { identity->type = NULL; @@ -1469,15 +1469,15 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - if (query != NULL) { + if (query) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); GSList *identities = NULL; GSList *features = NULL; - while (child != NULL) { + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) { const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR); - if (var != NULL) { + if (var) { features = g_slist_append(features, strdup(var)); } } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { @@ -1485,20 +1485,20 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); - if ((name != NULL) || (category != NULL) || (type != NULL)) { + if (name || category || type) { DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t)); - if (name != NULL) { + if (name) { identity->name = strdup(name); } else { identity->name = NULL; } - if (category != NULL) { + if (category) { identity->category = strdup(category); } else { identity->category = NULL; } - if (type != NULL) { + if (type) { identity->type = strdup(type); } else { identity->type = NULL; @@ -1534,17 +1534,17 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan log_debug("Response to query: %s", id); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - if (query != NULL) { + if (query) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); - while (child != NULL) { + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); - if ((stanza_name != NULL) && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) { + if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) { const char *item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); - if (item_jid != NULL) { + if (item_jid) { DiscoItem *item = malloc(sizeof(struct disco_item_t)); item->jid = strdup(item_jid); const char *item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); - if (item_name != NULL) { + if (item_name) { item->name = strdup(item_name); } else { item->name = NULL; From 8e64323503078ec8d24e4c5ce12ab22be097acfe Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:21:06 +0100 Subject: [PATCH 25/35] Use null check convention in presence.c --- src/xmpp/presence.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 0c6702b3..efb2e32d 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -171,7 +171,7 @@ presence_sub_request_exists(const char * const bare_jid) GSList *requests_p = autocomplete_create_list(sub_requests_ac); GSList *requests = requests_p; - while (requests != NULL) { + while (requests) { if (strcmp(requests->data, bare_jid) == 0) { result = TRUE; break; @@ -179,7 +179,7 @@ presence_sub_request_exists(const char * const bare_jid) requests = g_slist_next(requests); } - if (requests_p != NULL) { + if (requests_p) { g_slist_free_full(requests_p, free); } @@ -201,7 +201,7 @@ presence_update(const resource_presence_t presence_type, const char * const msg, return; } - if (msg != NULL) { + if (msg) { log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg); } else { @@ -246,11 +246,11 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) GList *rooms_p = muc_rooms(); GList *rooms = rooms_p; - while (rooms != NULL) { + while (rooms) { const char *room = rooms->data; const char *nick = muc_nick(room); - if (nick != NULL) { + if (nick) { char *full_room_jid = create_fulljid(room, nick); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); @@ -262,7 +262,7 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) rooms = g_list_next(rooms); } - if (rooms_p != NULL) { + if (rooms_p) { g_list_free(rooms_p); } } @@ -334,7 +334,7 @@ presence_leave_chat_room(const char * const room_jid) xmpp_conn_t *conn = connection_get_conn(); char *nick = muc_nick(room_jid); - if (nick != NULL) { + if (nick) { xmpp_stanza_t *presence = stanza_create_room_leave_presence(ctx, room_jid, nick); xmpp_send(conn, presence); @@ -351,11 +351,11 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); char *xmlns = NULL; - if (x != NULL) { + if (x) { xmlns = xmpp_stanza_get_ns(x); } char *type = NULL; - if (error_stanza != NULL) { + if (error_stanza) { type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); } @@ -365,7 +365,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *error_cond = NULL; xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_ns(error_stanza, STANZA_NS_STANZAS); - if (reason_st != NULL) { + if (reason_st) { error_cond = xmpp_stanza_get_name(reason_st); } if (error_cond == NULL) { @@ -385,15 +385,15 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *err_msg = stanza_get_error_message(stanza); GString *log_msg = g_string_new("presence stanza error received"); - if (id != NULL) { + if (id) { g_string_append(log_msg, " id="); g_string_append(log_msg, id); } - if (from != NULL) { + if (from) { g_string_append(log_msg, " from="); g_string_append(log_msg, from); } - if (type != NULL) { + if (type) { g_string_append(log_msg, " type="); g_string_append(log_msg, type); } @@ -404,7 +404,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - if (from != NULL) { + if (from) { ui_handle_recipient_error(from, err_msg); } else { ui_handle_error(err_msg); @@ -487,7 +487,7 @@ _unavailable_handler(xmpp_conn_t * const conn, char *status_str = stanza_get_status(stanza, NULL); if (strcmp(my_jid->barejid, from_jid->barejid) !=0) { - if (from_jid->resourcepart != NULL) { + if (from_jid->resourcepart) { sv_ev_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); // hack for servers that do not send full jid with unavailable presence @@ -495,7 +495,7 @@ _unavailable_handler(xmpp_conn_t * const conn, sv_ev_contact_offline(from_jid->barejid, "__prof_default", status_str); } } else { - if (from_jid->resourcepart != NULL) { + if (from_jid->resourcepart) { connection_remove_available_resource(from_jid->resourcepart); } } @@ -619,7 +619,7 @@ _send_caps_request(char *node, char *caps_key, char *id, char *from) xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_conn_t *conn = connection_get_conn(); - if (node != NULL) { + if (node) { log_debug("Node string: %s.", node); if (!caps_contains(caps_key)) { log_debug("Capabilities not cached for '%s', sending discovery IQ.", from); @@ -695,14 +695,14 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * free(reason); // kicked from room - } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { + } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_kicked(room, actor, reason); free(reason); // banned from room - } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { + } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_banned(room, actor, reason); @@ -740,14 +740,14 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * GSList *status_codes = stanza_get_status_codes_by_ns(stanza, STANZA_NS_MUC_USER); // kicked from room - if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { + if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_occupent_kicked(room, nick, actor, reason); free(reason); // banned from room - } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { + } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_occupent_banned(room, nick, actor, reason); From defa955ae022e691c12908a624170444eabd236f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:22:06 +0100 Subject: [PATCH 26/35] Use null check convention in roster.c --- src/xmpp/roster.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 84561ecf..71396c4d 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -132,7 +132,7 @@ roster_send_add_to_group(const char * const group, PContact contact) { GSList *groups = p_contact_groups(contact); GSList *new_groups = NULL; - while (groups != NULL) { + while (groups) { new_groups = g_slist_append(new_groups, strdup(groups->data)); groups = g_slist_next(groups); } @@ -142,7 +142,7 @@ roster_send_add_to_group(const char * const group, PContact contact) char *unique_id = create_unique_id(NULL); GroupData *data = malloc(sizeof(GroupData)); data->group = strdup(group); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { data->name = strdup(p_contact_name(contact)); } else { data->name = strdup(p_contact_barejid(contact)); @@ -162,7 +162,7 @@ static int _group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - if (userdata != NULL) { + if (userdata) { GroupData *data = userdata; ui_group_added(data->name, data->group); free(data->name); @@ -177,7 +177,7 @@ roster_send_remove_from_group(const char * const group, PContact contact) { GSList *groups = p_contact_groups(contact); GSList *new_groups = NULL; - while (groups != NULL) { + while (groups) { if (strcmp(groups->data, group) != 0) { new_groups = g_slist_append(new_groups, strdup(groups->data)); } @@ -191,7 +191,7 @@ roster_send_remove_from_group(const char * const group, PContact contact) char *unique_id = create_unique_id(NULL); GroupData *data = malloc(sizeof(GroupData)); data->group = strdup(group); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { data->name = strdup(p_contact_name(contact)); } else { data->name = strdup(p_contact_barejid(contact)); @@ -209,7 +209,7 @@ static int _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - if (userdata != NULL) { + if (userdata) { GroupData *data = userdata; ui_group_removed(data->name, data->group); free(data->name); @@ -235,7 +235,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // if from attribute exists and it is not current users barejid, ignore push Jid *my_jid = jid_create(jabber_get_fulljid()); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if ((from != NULL) && (strcmp(from, my_jid->barejid) != 0)) { + if (from && (strcmp(from, my_jid->barejid) != 0)) { jid_destroy(my_jid); return 1; } @@ -266,7 +266,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // check for pending out subscriptions gboolean pending_out = FALSE; - if ((ask != NULL) && (strcmp(ask, "subscribe") == 0)) { + if (ask && (strcmp(ask, "subscribe") == 0)) { pending_out = TRUE; } @@ -300,7 +300,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_children(query); - while (item != NULL) { + while (item) { const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); @@ -344,10 +344,10 @@ _get_groups_from_item(xmpp_stanza_t *item) GSList *groups = NULL; xmpp_stanza_t *group_element = xmpp_stanza_get_children(item); - while (group_element != NULL) { + while (group_element) { if (strcmp(xmpp_stanza_get_name(group_element), STANZA_NAME_GROUP) == 0) { char *groupname = xmpp_stanza_get_text(group_element); - if (groupname != NULL) { + if (groupname) { groups = g_slist_append(groups, groupname); } } From c487fe5f77e6bc0f11b63714d14e62e986eaa3ee Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:23:55 +0100 Subject: [PATCH 27/35] Use null check convention in stanza.c --- src/xmpp/stanza.c | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 84dcb797..1f25239b 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -141,7 +141,7 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid, xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "false"); } - if (nick != NULL) { + if (nick) { xmpp_stanza_t *nick_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(nick_st, STANZA_NAME_NICK); xmpp_stanza_set_text(nick_st, nick); @@ -374,7 +374,7 @@ stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id, xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_SET); - if (id != NULL) { + if (id) { xmpp_stanza_set_id(iq, id); } @@ -386,13 +386,13 @@ stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id, xmpp_stanza_set_name(item, STANZA_NAME_ITEM); xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid); - if (handle != NULL) { + if (handle) { xmpp_stanza_set_attribute(item, STANZA_ATTR_NAME, handle); } else { xmpp_stanza_set_attribute(item, STANZA_ATTR_NAME, ""); } - while (groups != NULL) { + while (groups) { xmpp_stanza_t *group = xmpp_stanza_new(ctx); xmpp_stanza_t *groupname = xmpp_stanza_new(ctx); xmpp_stanza_set_name(group, STANZA_NAME_GROUP); @@ -464,7 +464,7 @@ stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room, xmpp_stanza_set_name(invite, STANZA_NAME_INVITE); xmpp_stanza_set_attribute(invite, STANZA_ATTR_TO, contact); - if (reason != NULL) { + if (reason) { xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON); xmpp_stanza_t *reason_txt = xmpp_stanza_new(ctx); @@ -499,7 +499,7 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx, xmpp_stanza_set_ns(x, STANZA_NS_MUC); // if a password was given - if (passwd != NULL) { + if (passwd) { xmpp_stanza_t *pass = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pass, "password"); xmpp_stanza_t *text = xmpp_stanza_new(ctx); @@ -893,7 +893,7 @@ stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char * const id, const char * xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); xmpp_stanza_set_ns(query, XMPP_NS_DISCO_INFO); - if (node != NULL) { + if (node) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node); } @@ -964,7 +964,7 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx, const char * const target) xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_GET); - if (target != NULL) { + if (target) { xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, target); } char *id = create_unique_id("ping"); @@ -987,11 +987,11 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) { // first check for XEP-0203 delayed delivery xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY); - if (delay != NULL) { + if (delay) { char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS); - if ((xmlns != NULL) && (strcmp(xmlns, "urn:xmpp:delay") == 0)) { + if (xmlns && (strcmp(xmlns, "urn:xmpp:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP); - if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) { + if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) { return TRUE; } } @@ -1000,11 +1000,11 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) // otherwise check for XEP-0091 legacy delayed delivery // stanp format : CCYYMMDDThh:mm:ss xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); - if (x != NULL) { + if (x) { char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS); - if ((xmlns != NULL) && (strcmp(xmlns, "jabber:x:delay") == 0)) { + if (xmlns && (strcmp(xmlns, "jabber:x:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP); - if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) { + if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) { return TRUE; } } @@ -1020,17 +1020,17 @@ stanza_get_status(xmpp_stanza_t *stanza, char *def) xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS); - if (status != NULL) { + if (status) { // xmpp_free and free may be different functions so convert all to // libc malloc char *s1, *s2 = NULL; s1 = xmpp_stanza_get_text(status); - if (s1 != NULL) { + if (s1) { s2 = strdup(s1); xmpp_free(ctx, s1); } return s2; - } else if (def != NULL) { + } else if (def) { return strdup(def); } else { return NULL; @@ -1044,17 +1044,17 @@ stanza_get_show(xmpp_stanza_t *stanza, char *def) xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SHOW); - if (show != NULL) { + if (show) { // xmpp_free and free may be different functions so convert all to // libc malloc char *s1, *s2 = NULL; s1 = xmpp_stanza_get_text(show); - if (s1 != NULL) { + if (s1) { s2 = strdup(s1); xmpp_free(ctx, s1); } return s2; - } else if (def != NULL) { + } else if (def) { return strdup(def); } else { return NULL; @@ -1090,7 +1090,7 @@ stanza_muc_requires_config(xmpp_stanza_t * const stanza) // muc user namespaced x element xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - if (x != NULL) { + if (x) { // check for item element with owner affiliation xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, "item"); @@ -1104,7 +1104,7 @@ stanza_muc_requires_config(xmpp_stanza_t * const stanza) // check for status code 201 xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) { char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE); if (g_strcmp0(code, "201") == 0) { @@ -1346,11 +1346,11 @@ stanza_is_room_nick_change(xmpp_stanza_t * const stanza) // muc user namespaced x element xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - if (x != NULL) { + if (x) { // check for status child element with 303 code xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) { char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE); if (g_strcmp0(code, "303") == 0) { @@ -1374,7 +1374,7 @@ stanza_get_new_nick(xmpp_stanza_t * const stanza) xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (strcmp(xmpp_stanza_get_name(x_children), STANZA_NAME_ITEM) == 0) { char *nick = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_NICK); if (nick) { @@ -1488,9 +1488,9 @@ stanza_get_error_message(xmpp_stanza_t *stanza) xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT); // check for text - if (text_stanza != NULL) { + if (text_stanza) { gchar *err_msg = xmpp_stanza_get_text(text_stanza); - if (err_msg != NULL) { + if (err_msg) { char *result = strdup(err_msg); xmpp_free(ctx, err_msg); return result; @@ -1525,7 +1525,7 @@ stanza_get_error_message(xmpp_stanza_t *stanza) int i; for (i = 0; i < ARRAY_SIZE(defined_conditions); i++) { xmpp_stanza_t *cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]); - if (cond_stanza != NULL) { + if (cond_stanza) { char *result = strdup(xmpp_stanza_get_name(cond_stanza)); return result; } @@ -1562,7 +1562,7 @@ void stanza_attach_show(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, const char * const show) { - if (show != NULL) { + if (show) { xmpp_stanza_t *show_stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(show_stanza, STANZA_NAME_SHOW); xmpp_stanza_t *text = xmpp_stanza_new(ctx); @@ -1578,7 +1578,7 @@ void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, const char * const status) { - if (status != NULL) { + if (status) { xmpp_stanza_t *status_stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(status_stanza, STANZA_NAME_STATUS); xmpp_stanza_t *text = xmpp_stanza_new(ctx); @@ -1725,9 +1725,9 @@ stanza_parse_presence(xmpp_stanza_t *stanza, int *err) result->priority = 0; xmpp_stanza_t *priority_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PRIORITY); - if (priority_stanza != NULL) { + if (priority_stanza) { char *priority_str = xmpp_stanza_get_text(priority_stanza); - if (priority_str != NULL) { + if (priority_str) { result->priority = atoi(priority_str); } free(priority_str); From 49e450767db2c9d025fe124b824226849bb2bea1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:24:37 +0100 Subject: [PATCH 28/35] Use null check convention in chat_session.c --- src/chat_session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chat_session.c b/src/chat_session.c index 8ce2e437..2758d603 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -64,7 +64,7 @@ _chat_session_new(const char * const barejid, const char * const resource, static void _chat_session_free(ChatSession *session) { - if (session != NULL) { + if (session) { free(session->barejid); free(session->resource); free(session); @@ -81,7 +81,7 @@ chat_sessions_init(void) void chat_sessions_clear(void) { - if (sessions != NULL) + if (sessions) g_hash_table_remove_all(sessions); } From 1d002e5bdc4347502bd4b87e147f54e322944250 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:26:08 +0100 Subject: [PATCH 29/35] Use null check convention in common.c --- src/common.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common.c b/src/common.c index 653be720..772e24d3 100644 --- a/src/common.c +++ b/src/common.c @@ -287,7 +287,7 @@ prof_getline(FILE *stream) result = (char *)realloc(s, s_size + buf_size); if (result == NULL) { - if (s != NULL) { + if (s) { free(s); s = NULL; } @@ -325,7 +325,7 @@ release_get_latest() curl_easy_perform(handle); curl_easy_cleanup(handle); - if (output.buffer != NULL) { + if (output.buffer) { output.buffer[output.size++] = '\0'; return output.buffer; } else { @@ -432,10 +432,10 @@ gchar * xdg_get_config_home(void) { gchar *xdg_config_home = getenv("XDG_CONFIG_HOME"); - if (xdg_config_home != NULL) + if (xdg_config_home) g_strstrip(xdg_config_home); - if ((xdg_config_home != NULL) && (strcmp(xdg_config_home, "") != 0)) { + if (xdg_config_home && (strcmp(xdg_config_home, "") != 0)) { return strdup(xdg_config_home); } else { GString *default_path = g_string_new(getenv("HOME")); @@ -451,10 +451,10 @@ gchar * xdg_get_data_home(void) { gchar *xdg_data_home = getenv("XDG_DATA_HOME"); - if (xdg_data_home != NULL) + if (xdg_data_home) g_strstrip(xdg_data_home); - if ((xdg_data_home != NULL) && (strcmp(xdg_data_home, "") != 0)) { + if (xdg_data_home && (strcmp(xdg_data_home, "") != 0)) { return strdup(xdg_data_home); } else { GString *default_path = g_string_new(getenv("HOME")); @@ -474,7 +474,7 @@ create_unique_id(char *prefix) GString *result_str = g_string_new(""); unique_id++; - if (prefix != NULL) { + if (prefix) { g_string_printf(result_str, "prof_%s_%lu", prefix, unique_id); } else { g_string_printf(result_str, "prof_%lu", unique_id); @@ -543,7 +543,7 @@ get_next_available_win_num(GList *used) curr = sorted; // skip console curr = g_list_next(curr); - while (curr != NULL) { + while (curr) { int curr_num = GPOINTER_TO_INT(curr->data); if (((last_num != 9) && ((last_num + 1) != curr_num)) || @@ -622,14 +622,14 @@ strip_arg_quotes(const char * const input) char *unquoted = strdup(input); // Remove starting quote if it exists - if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, '"')) { if(strchr(unquoted, ' ') + 1 == strchr(unquoted, '"')) { memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); } } // Remove ending quote if it exists - if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, '"')) { if(strchr(unquoted, '\0') - 1 == strchr(unquoted, '"')) { memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); } From 1bfaa49fb3cd61878c85eb5bfad202a798fb8b0a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:26:57 +0100 Subject: [PATCH 30/35] Use null check convention in contact.c --- src/contact.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/contact.c b/src/contact.c index cd7d5d9d..993ede7c 100644 --- a/src/contact.c +++ b/src/contact.c @@ -63,7 +63,7 @@ p_contact_new(const char * const barejid, const char * const name, PContact contact = malloc(sizeof(struct p_contact_t)); contact->barejid = strdup(barejid); - if (name != NULL) { + if (name) { contact->name = strdup(name); } else { contact->name = NULL; @@ -71,12 +71,12 @@ p_contact_new(const char * const barejid, const char * const name, contact->groups = groups; - if (subscription != NULL) + if (subscription) contact->subscription = strdup(subscription); else contact->subscription = strdup("none"); - if (offline_message != NULL) + if (offline_message) contact->offline_message = strdup(offline_message); else contact->offline_message = NULL; @@ -96,7 +96,7 @@ void p_contact_set_name(const PContact contact, const char * const name) { FREE_SET_NULL(contact->name); - if (name != NULL) { + if (name) { contact->name = strdup(name); } } @@ -104,7 +104,7 @@ p_contact_set_name(const PContact contact, const char * const name) void p_contact_set_groups(const PContact contact, GSList *groups) { - if (contact->groups != NULL) { + if (contact->groups) { g_slist_free_full(contact->groups, g_free); contact->groups = NULL; } @@ -116,7 +116,7 @@ gboolean p_contact_in_group(const PContact contact, const char * const group) { GSList *groups = contact->groups; - while (groups != NULL) { + while (groups) { if (strcmp(groups->data, group) == 0) { return TRUE; } @@ -144,17 +144,17 @@ p_contact_remove_resource(PContact contact, const char * const resource) void p_contact_free(PContact contact) { - if (contact != NULL) { + if (contact) { free(contact->barejid); free(contact->name); free(contact->subscription); free(contact->offline_message); - if (contact->groups != NULL) { + if (contact->groups) { g_slist_free_full(contact->groups, g_free); } - if (contact->last_activity != NULL) { + if (contact->last_activity) { g_date_time_unref(contact->last_activity); } @@ -179,7 +179,7 @@ p_contact_name(const PContact contact) const char * p_contact_name_or_jid(const PContact contact) { - if (contact->name != NULL) { + if (contact->name) { return contact->name; } else { return contact->barejid; @@ -247,7 +247,7 @@ _get_most_available_resource(PContact contact) Resource *current = curr->data; Resource *highest = current; curr = g_list_next(curr); - while (curr != NULL) { + while (curr) { current = curr->data; // priority is same as current highest, choose presence @@ -388,7 +388,7 @@ void p_contact_set_subscription(const PContact contact, const char * const subscription) { FREE_SET_NULL(contact->subscription); - if (subscription != NULL) { + if (subscription) { contact->subscription = strdup(subscription); } } @@ -402,12 +402,12 @@ p_contact_set_pending_out(const PContact contact, gboolean pending_out) void p_contact_set_last_activity(const PContact contact, GDateTime *last_activity) { - if (contact->last_activity != NULL) { + if (contact->last_activity) { g_date_time_unref(contact->last_activity); contact->last_activity = NULL; } - if (last_activity != NULL) { + if (last_activity) { contact->last_activity = g_date_time_ref(last_activity); } } From 4c78534be0e78be94bc7cd23ec1e2f644ebbd27f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:27:41 +0100 Subject: [PATCH 31/35] Use null check convention in jid.c --- src/jid.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jid.c b/src/jid.c index 0a722b1e..baeeb279 100644 --- a/src/jid.c +++ b/src/jid.c @@ -80,12 +80,12 @@ jid_create(const gchar * const str) gchar *domain_start = trimmed; - if (atp != NULL) { + if (atp) { result->localpart = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, atp)); domain_start = atp + 1; } - if (slashp != NULL) { + if (slashp) { result->resourcepart = g_strdup(slashp + 1); result->domainpart = g_utf8_substring(domain_start, 0, g_utf8_pointer_to_offset(domain_start, slashp)); char *barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp)); @@ -120,7 +120,7 @@ jid_create_from_bare_and_resource(const char * const room, const char * const ni void jid_destroy(Jid *jid) { - if (jid != NULL) { + if (jid) { g_free(jid->str); g_free(jid->localpart); g_free(jid->domainpart); @@ -169,8 +169,8 @@ get_nick_from_full_jid(const char * const full_room_jid) char **tokens = g_strsplit(full_room_jid, "/", 0); char *nick_part = NULL; - if (tokens != NULL) { - if (tokens[0] != NULL && tokens[1] != NULL) { + if (tokens) { + if (tokens[0] && tokens[1]) { nick_part = strdup(tokens[1]); } From 41724218c0ca8be94906001f22c87af423e8540c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:28:34 +0100 Subject: [PATCH 32/35] Use null check convention in log.c --- src/log.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/log.c b/src/log.c index ac0dfd2e..a7727e8b 100644 --- a/src/log.c +++ b/src/log.c @@ -166,7 +166,7 @@ log_close(void) { g_string_free(mainlogfile, TRUE); g_time_zone_unref(tz); - if (logp != NULL) { + if (logp) { fclose(logp); } } @@ -174,7 +174,7 @@ log_close(void) void log_msg(log_level_t level, const char * const area, const char * const msg) { - if (level >= level_filter && logp != NULL) { + if (level >= level_filter && logp) { dt = g_date_time_new_now(tz); char *level_str = _log_string_from_level(level); @@ -347,7 +347,7 @@ _chat_log_chat(const char * const login, const char * const other, FILE *logp = fopen(dated_log->filename, "a"); g_chmod(dated_log->filename, S_IRUSR | S_IWUSR); - if (logp != NULL) { + if (logp) { if (direction == PROF_IN_LOG) { if (strncmp(msg, "/me ", 4) == 0) { fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4); @@ -396,7 +396,7 @@ groupchat_log_chat(const gchar * const login, const gchar * const room, FILE *logp = fopen(dated_log->filename, "a"); g_chmod(dated_log->filename, S_IRUSR | S_IWUSR); - if (logp != NULL) { + if (logp) { if (strncmp(msg, "/me ", 4) == 0) { fprintf(logp, "%s - *%s %s\n", date_fmt, nick, msg + 4); } else { @@ -433,7 +433,7 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient) char *filename = _get_log_filename(recipient, login, log_date, FALSE); FILE *logp = fopen(filename, "r"); - if (logp != NULL) { + if (logp) { GString *header = g_string_new(""); g_string_append_printf(header, "%d/%d/%d:", g_date_time_get_day_of_month(log_date), @@ -518,12 +518,12 @@ _log_roll_needed(struct dated_chat_log *dated_log) static void _free_chat_log(struct dated_chat_log *dated_log) { - if (dated_log != NULL) { - if (dated_log->filename != NULL) { + if (dated_log) { + if (dated_log->filename) { g_free(dated_log->filename); dated_log->filename = NULL; } - if (dated_log->date != NULL) { + if (dated_log->date) { g_date_time_unref(dated_log->date); dated_log->date = NULL; } From 0930f0f688bc9784b66f8531c4337eaa1106b92a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:29:24 +0100 Subject: [PATCH 33/35] Use null check convention in profanity.c --- src/profanity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index 6a2966dd..4330b718 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -112,14 +112,14 @@ prof_handle_idle(void) GSList *recipients = ui_get_chat_recipients(); GSList *curr = recipients; - while (curr != NULL) { + while (curr) { char *barejid = curr->data; ProfChatWin *chatwin = wins_get_chat(barejid); chat_state_handle_idle(chatwin->barejid, chatwin->state); curr = g_slist_next(curr); } - if (recipients != NULL) { + if (recipients) { g_slist_free(recipients); } } From 59788752c7269ef30f25e35bf7fdecb2db3fb2b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:29:53 +0100 Subject: [PATCH 34/35] Use null check convention in resource.c --- src/resource.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resource.c b/src/resource.c index 620dd38d..1598c7b2 100644 --- a/src/resource.c +++ b/src/resource.c @@ -46,7 +46,7 @@ Resource * resource_new(const char * const name, resource_presence_t presence, Resource *new_resource = malloc(sizeof(struct resource_t)); new_resource->name = strdup(name); new_resource->presence = presence; - if (status != NULL) { + if (status) { new_resource->status = strdup(status); } else { new_resource->status = NULL; @@ -88,7 +88,7 @@ resource_compare_availability(Resource *first, Resource *second) void resource_destroy(Resource *resource) { - if (resource != NULL) { + if (resource) { free(resource->name); free(resource->status); free(resource); From 6f3750c6aa1ba72378ac004e6abceb19ed1ddecb Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:31:05 +0100 Subject: [PATCH 35/35] Use null check convention in roster_list.c --- src/roster_list.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/roster_list.c b/src/roster_list.c index a320ab2b..d5e1c4a0 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -123,8 +123,8 @@ roster_get_msg_display_name(const char * const barejid, const char * const resou GString *result = g_string_new(""); PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { g_string_append(result, p_contact_name(contact)); } else { g_string_append(result, barejid); @@ -206,7 +206,7 @@ roster_change_name(PContact contact, const char * const new_name) const char *current_name = NULL; const char *barejid = p_contact_barejid(contact); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { current_name = strdup(p_contact_name(contact)); } @@ -223,9 +223,9 @@ roster_remove(const char * const name, const char * const barejid) // remove each fulljid PContact contact = roster_get_contact(barejid); - if (contact != NULL) { + if (contact) { GList *resources = p_contact_get_available_resources(contact); - while (resources != NULL) { + while (resources) { GString *fulljid = g_string_new(strdup(barejid)); g_string_append(fulljid, "/"); g_string_append(fulljid, resources->data); @@ -252,7 +252,7 @@ roster_update(const char * const barejid, const char * const name, const char * const new_name = name; const char * current_name = NULL; - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { current_name = strdup(p_contact_name(contact)); } @@ -261,7 +261,7 @@ roster_update(const char * const barejid, const char * const name, _replace_name(current_name, new_name, barejid); // add groups - while (groups != NULL) { + while (groups) { autocomplete_add(groups_ac, groups->data); groups = g_slist_next(groups); } @@ -272,7 +272,7 @@ roster_add(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { PContact contact = roster_get_contact(barejid); - if (contact != NULL) { + if (contact) { return FALSE; } @@ -280,7 +280,7 @@ roster_add(const char * const barejid, const char * const name, GSList *groups, pending_out); // add groups - while (groups != NULL) { + while (groups) { autocomplete_add(groups_ac, groups->data); groups = g_slist_next(groups); } @@ -418,7 +418,7 @@ roster_get_group(const char * const group) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { GSList *groups = p_contact_groups(value); - while (groups != NULL) { + while (groups) { if (strcmp(groups->data, group) == 0) { result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); break; @@ -477,12 +477,12 @@ _replace_name(const char * const current_name, const char * const new_name, const char * const barejid) { // current handle exists already - if (current_name != NULL) { + if (current_name) { autocomplete_remove(name_ac, current_name); g_hash_table_remove(name_to_barejid, current_name); _add_name_and_barejid(new_name, barejid); // no current handle - } else if (new_name != NULL) { + } else if (new_name) { autocomplete_remove(name_ac, barejid); g_hash_table_remove(name_to_barejid, barejid); _add_name_and_barejid(new_name, barejid); @@ -492,7 +492,7 @@ _replace_name(const char * const current_name, const char * const new_name, static void _add_name_and_barejid(const char * const name, const char * const barejid) { - if (name != NULL) { + if (name) { autocomplete_add(name_ac, name); g_hash_table_insert(name_to_barejid, strdup(name), strdup(barejid)); } else { @@ -507,12 +507,12 @@ gint _compare_contacts(PContact a, PContact b) const char * utf8_str_a = NULL; const char * utf8_str_b = NULL; - if (p_contact_name(a) != NULL) { + if (p_contact_name(a)) { utf8_str_a = p_contact_name(a); } else { utf8_str_a = p_contact_barejid(a); } - if (p_contact_name(b) != NULL) { + if (p_contact_name(b)) { utf8_str_b = p_contact_name(b); } else { utf8_str_b = p_contact_barejid(b);