Change all strcmp() to g_strcmp0() to handle nulls gracefully

Just a string replacement (but i did check every one of them)

    sed -i 's/strcmp(/g_strcmp0(/g' **/*.c
This commit is contained in:
dequis 2015-04-07 22:39:05 -03:00
commit f14199d9c1
57 changed files with 170 additions and 170 deletions

View file

@ -42,7 +42,7 @@ void command_history_add(HISTORY_REC *history, const char *text)
g_return_if_fail(text != NULL);
link = g_list_last(history->list);
if (link != NULL && strcmp(link->data, text) == 0)
if (link != NULL && g_strcmp0(link->data, text) == 0)
return; /* same as previous entry */
if (settings_get_int("max_command_history") < 1 ||
@ -121,7 +121,7 @@ const char *command_history_prev(WINDOW_REC *window, const char *text)
}
if (*text != '\0' &&
(pos == NULL || strcmp(pos->data, text) != 0)) {
(pos == NULL || g_strcmp0(pos->data, text) != 0)) {
/* save the old entry to history */
command_history_add(history, text);
}
@ -145,7 +145,7 @@ const char *command_history_next(WINDOW_REC *window, const char *text)
}
if (*text != '\0' &&
(pos == NULL || strcmp(pos->data, text) != 0)) {
(pos == NULL || g_strcmp0(pos->data, text) != 0)) {
/* save the old entry to history */
command_history_add(history, text);
}

View file

@ -141,7 +141,7 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i
g_return_val_if_fail(pos != NULL, NULL);
continue_complete = complist != NULL && *pos == last_line_pos &&
strcmp(line, last_line) == 0;
g_strcmp0(line, last_line) == 0;
if (erase && !continue_complete)
return NULL;
@ -681,7 +681,7 @@ static void sig_complete_set(GList **list, WINDOW_REC *window,
g_return_if_fail(line != NULL);
if (*line == '\0' ||
!strcmp("-clear", line) || !strcmp("-default", line))
!g_strcmp0("-clear", line) || !g_strcmp0("-default", line))
*list = completion_get_settings(word, -1);
else if (*line != '\0' && *word == '\0') {
SETTINGS_REC *rec = settings_get_record(line);

View file

@ -287,7 +287,7 @@ static void cmd_channel_add(const char *data)
if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
signal_emit("channel add fill", 2, rec, optlist);
@ -523,7 +523,7 @@ static void cmd_names(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
"names", &optlist, &channel))
return;
if (strcmp(channel, "*") == 0 || *channel == '\0') {
if (g_strcmp0(channel, "*") == 0 || *channel == '\0') {
if (!IS_CHANNEL(item))
cmd_param_error(CMDERR_NOT_JOINED);
@ -561,7 +561,7 @@ static void cmd_names(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
if (unknowns->len > 1)
g_string_truncate(unknowns, unknowns->len-1);
if (unknowns->len > 0 && strcmp(channel, unknowns->str) != 0)
if (unknowns->len > 0 && g_strcmp0(channel, unknowns->str) != 0)
signal_emit("command names", 3, unknowns->str, server, item);
g_string_free(unknowns, TRUE);

View file

@ -161,7 +161,7 @@ static PROCESS_REC *process_find(const char *name, int verbose)
for (tmp = processes; tmp != NULL; tmp = tmp->next) {
PROCESS_REC *rec = tmp->data;
if (rec->name != NULL && strcmp(rec->name, name) == 0)
if (rec->name != NULL && g_strcmp0(rec->name, name) == 0)
return rec;
}

View file

@ -37,12 +37,12 @@ static int commands_equal(COMMAND_REC *rec, COMMAND_REC *rec2)
if (rec2->category == NULL && rec->category != NULL)
return 1;
if (rec->category != NULL && rec2->category != NULL) {
i = strcmp(rec->category, rec2->category);
i = g_strcmp0(rec->category, rec2->category);
if (i != 0)
return i;
}
return strcmp(rec->cmd, rec2->cmd);
return g_strcmp0(rec->cmd, rec2->cmd);
}
static int get_cmd_length(void *data)
@ -176,7 +176,7 @@ static void show_help(const char *data)
if (last != NULL && rec->category != NULL &&
(last->category == NULL ||
strcmp(rec->category, last->category) != 0)) {
g_strcmp0(rec->category, last->category) != 0)) {
/* category changed */
if (items > 0) {
if (!header) {

View file

@ -165,7 +165,7 @@ static void cmd_ignore(const char *data)
rec = g_new0(IGNORE_REC, 1);
rec->mask = mask == NULL || *mask == '\0' ||
strcmp(mask, "*") == 0 ? NULL : g_strdup(mask);
g_strcmp0(mask, "*") == 0 ? NULL : g_strdup(mask);
rec->channels = channels;
} else {
g_free_and_null(rec->pattern);

View file

@ -485,7 +485,7 @@ static void autolog_open_check(TEXT_DEST_REC *dest)
return;
if (target != NULL)
autolog_open(server, server_tag, strcmp(target, "*") ? target : deftarget);
autolog_open(server, server_tag, g_strcmp0(target, "*") ? target : deftarget);
}
static void log_single_line(WINDOW_REC *window, const char *server_tag,
@ -629,7 +629,7 @@ static void sig_log_create_failed(LOG_REC *log)
static void sig_log_new(LOG_REC *log)
{
if (!settings_get_bool("awaylog_colors") &&
strcmp(log->fname, settings_get_str("awaylog_file")) == 0)
g_strcmp0(log->fname, settings_get_str("awaylog_file")) == 0)
log->colorizer = log_colorizer_strip;
}

View file

@ -249,7 +249,7 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
int level = MSGLEVEL_MSGS;
/* own message returned by bouncer? */
int own = (!strcmp(nick, server->nick));
int own = (!g_strcmp0(nick, server->nick));
query = query_find(server, own ? target : nick);
@ -323,8 +323,8 @@ static void sig_message_own_private(SERVER_REC *server, const char *msg,
/* this should only happen if some special target failed and
we should display some error message. currently the special
targets are only ',' and '.'. */
g_return_if_fail(strcmp(origtarget, ",") == 0 ||
strcmp(origtarget, ".") == 0);
g_return_if_fail(g_strcmp0(origtarget, ",") == 0 ||
g_strcmp0(origtarget, ".") == 0);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
*origtarget == ',' ? TXT_NO_MSGS_GOT :
@ -569,7 +569,7 @@ static int printnick_exists(NICK_REC *first, NICK_REC *ignore,
while (first != NULL) {
if (first != ignore) {
printnick = g_hash_table_lookup(printnicks, first);
if (printnick != NULL && strcmp(printnick, nick) == 0)
if (printnick != NULL && g_strcmp0(printnick, nick) == 0)
return TRUE;
}

View file

@ -331,7 +331,7 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
QUERY_REC *query;
/* own message returned by bouncer? */
int own = (!strcmp(nick, server->nick));
int own = (!g_strcmp0(nick, server->nick));
/* create query window if needed */
query = privmsg_get_query(server, own ? target : nick, FALSE, MSGLEVEL_MSGS);

View file

@ -45,7 +45,7 @@ static const char *fe_recode_get_target (WI_ITEM_REC *witem)
static int fe_recode_compare_func (CONFIG_NODE *node1, CONFIG_NODE *node2)
{
return strcmp(node1->key, node2->key);
return g_strcmp0(node1->key, node2->key);
}
/* SYNTAX: RECODE */

View file

@ -185,7 +185,7 @@ static void cmd_server_add(const char *data)
if (g_hash_table_lookup(optlist, "proxy")) rec->no_proxy = FALSE;
if (g_hash_table_lookup(optlist, "noproxy")) rec->no_proxy = TRUE;
if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);
value = g_hash_table_lookup(optlist, "host");
if (value != NULL && *value != '\0') {
rec->own_host = g_strdup(value);
@ -264,7 +264,7 @@ static void cmd_server_connect(const char *data)
"connect", &optlist, &addr))
return;
if (*addr == '\0' || strcmp(addr, "+") == 0)
if (*addr == '\0' || g_strcmp0(addr, "+") == 0)
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (*addr == '+') window_create(NULL, FALSE);

View file

@ -53,7 +53,7 @@ static void set_print_pattern(const char *pattern)
if (stristr(rec->key, pattern) == NULL)
continue;
if (strcmp(last_section, rec->section) != 0) {
if (g_strcmp0(last_section, rec->section) != 0) {
/* print section */
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
TXT_SET_TITLE, rec->section);

View file

@ -168,7 +168,7 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels)
if ((channels == NULL && rec->channels == NULL))
return rec; /* no channels - ok */
if (channels != NULL && strcmp(*channels, "*") == 0)
if (channels != NULL && g_strcmp0(*channels, "*") == 0)
return rec; /* ignore channels */
if (channels == NULL || rec->channels == NULL)
@ -306,7 +306,7 @@ void hilight_update_text_dest(TEXT_DEST_REC *dest, HILIGHT_REC *rec)
dest->hilight_priority = rec->priority;
g_free_and_null(dest->hilight_color);
if (rec->act_color != NULL && strcmp(rec->act_color, "%n") == 0)
if (rec->act_color != NULL && g_strcmp0(rec->act_color, "%n") == 0)
dest->level |= MSGLEVEL_NO_ACT;
else
dest->hilight_color = hilight_get_act_color(rec);

View file

@ -118,7 +118,7 @@ static CONFIG_NODE *key_config_find(const char *key)
for (; tmp != NULL; tmp = config_node_next(tmp)) {
node = tmp->data;
if (strcmp(config_node_get_str(node, "key", ""), key) == 0)
if (g_strcmp0(config_node_get_str(node, "key", ""), key) == 0)
return node;
}
@ -211,7 +211,7 @@ static int expand_combo(const char *start, const char *end, GSList **out)
for (tmp = info->keys; tmp != NULL; tmp = tmp->next) {
KEY_REC *rec = tmp->data;
if (strcmp(rec->data, str) == 0)
if (g_strcmp0(rec->data, str) == 0)
list = g_slist_append(list, rec);
}
@ -347,7 +347,7 @@ static void key_states_scan_key(const char *key, KEY_REC *rec)
{
GSList *tmp, *out;
if (strcmp(rec->info->id, "key") == 0)
if (g_strcmp0(rec->info->id, "key") == 0)
return;
out = g_slist_append(NULL, g_string_new(NULL));
@ -383,7 +383,7 @@ static void key_states_rescan(void)
g_tree_foreach(key_states, (GTraverseFunc) key_state_destroy,
NULL);
g_tree_destroy(key_states);
key_states = g_tree_new((GCompareFunc) strcmp);
key_states = g_tree_new((GCompareFunc) g_strcmp0);
temp = g_string_new(NULL);
g_hash_table_foreach(keys, (GHFunc) key_states_scan_key, temp);
@ -860,7 +860,7 @@ void keyboard_init(void)
default_keys = g_hash_table_new((GHashFunc) g_str_hash,
(GCompareFunc) g_str_equal);
keyinfos = NULL;
key_states = g_tree_new((GCompareFunc) strcmp);
key_states = g_tree_new((GCompareFunc) g_strcmp0);
key_config_frozen = 0;
memset(used_keys, 0, sizeof(used_keys));

View file

@ -895,7 +895,7 @@ THEME_REC *theme_load(const char *setname)
name = g_strdup(setname);
p = strrchr(name, '.');
if (p != NULL && strcmp(p, ".theme") == 0) {
if (p != NULL && g_strcmp0(p, ".theme") == 0) {
/* remove the trailing .theme */
*p = '\0';
}
@ -1358,9 +1358,9 @@ static void read_settings(void)
theme = settings_get_str("theme");
len = strlen(current_theme->name);
if (strcmp(current_theme->name, theme) != 0 &&
if (g_strcmp0(current_theme->name, theme) != 0 &&
(strncmp(current_theme->name, theme, len) != 0 ||
strcmp(theme+len, ".theme") != 0))
g_strcmp0(theme+len, ".theme") != 0))
change_theme(theme, TRUE);
}

View file

@ -127,7 +127,7 @@ static void cmd_window_info(WINDOW_REC *win)
win->active_server->tag : "NONE");
} else {
if (win->active_server != NULL &&
strcmp(win->active_server->tag, win->servertag) != 0)
g_strcmp0(win->active_server->tag, win->servertag) != 0)
g_warning("Active server isn't the sticky server!");
printformat_window(win, MSGLEVEL_CLIENTCRAP,
@ -609,7 +609,7 @@ static void cmd_window_name(const char *data)
if (win == NULL || win == active_win)
window_set_name(active_win, data);
else if (active_win->name == NULL ||
strcmp(active_win->name, data) != 0) {
g_strcmp0(active_win->name, data) != 0) {
printformat_window(active_win, MSGLEVEL_CLIENTERROR,
TXT_WINDOW_NAME_NOT_UNIQUE, data);
}

View file

@ -243,7 +243,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
return;
/* handle only DCC messages */
if (strcmp(target, "*") == 0)
if (g_strcmp0(target, "*") == 0)
dcc = item_get_dcc(item);
else if (*target == '=')
dcc = dcc_chat_find_id(target+1);

View file

@ -427,7 +427,7 @@ static void event_no_such_nick(IRC_SERVER_REC *server, const char *data,
g_return_if_fail(data != NULL);
params = event_get_params(data, 2, NULL, &unick);
if (!strcmp(unick, "*"))
if (!g_strcmp0(unick, "*"))
/* more information will be in the description,
* e.g. * :Target left IRC. Failed to deliver: [hi] */
print_event_received(server, data, nick, FALSE);
@ -605,7 +605,7 @@ static void print_event_received(IRC_SERVER_REC *server, const char *data,
recoded = recode_in(SERVER(server), args, NULL);
format = nick == NULL || server->real_address == NULL ||
strcmp(nick, server->real_address) == 0 ?
g_strcmp0(nick, server->real_address) == 0 ?
IRCTXT_DEFAULT_EVENT : IRCTXT_DEFAULT_EVENT_SERVER;
printformat(server, target, MSGLEVEL_CRAP, format,
nick, recoded, current_server_event);

View file

@ -110,7 +110,7 @@ static void cmd_notice(const char *data, IRC_SERVER_REC *server,
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
&target, &msg))
return;
if (strcmp(target, "*") == 0)
if (g_strcmp0(target, "*") == 0)
target = item == NULL ? "" : window_item_get_target(item);
if (*target == '\0' || *msg == '\0')
@ -133,7 +133,7 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server,
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
&target, &ctcpcmd, &ctcpdata))
return;
if (strcmp(target, "*") == 0)
if (g_strcmp0(target, "*") == 0)
target = item == NULL ? "" : window_item_get_target(item);
if (*target == '\0' || *ctcpcmd == '\0')
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
@ -162,7 +162,7 @@ static void cmd_nctcp(const char *data, IRC_SERVER_REC *server,
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
&target, &text))
return;
if (strcmp(target, "*") == 0)
if (g_strcmp0(target, "*") == 0)
target = item == NULL ? "" : window_item_get_target(item);
if (*target == '\0' || *text == '\0')
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
@ -262,7 +262,7 @@ static void cmd_ban(const char *data, IRC_SERVER_REC *server,
if (chanrec == NULL && *channel == '\0')
cmd_param_error(CMDERR_NOT_JOINED);
if (*channel != '\0' && strcmp(channel, "*") != 0)
if (*channel != '\0' && g_strcmp0(channel, "*") != 0)
chanrec = irc_channel_find(server, channel);
if (chanrec == NULL || !chanrec->synced) {

View file

@ -178,7 +178,7 @@ static void sig_message_irc_action(IRC_SERVER_REC *server, const char *msg,
if (ischannel(*target)) {
item = irc_channel_find(server, target);
} else {
own = (!strcmp(nick, server->nick));
own = (!g_strcmp0(nick, server->nick));
item = privmsg_get_query(SERVER(server), own ? target : nick, FALSE, level);
}

View file

@ -135,7 +135,7 @@ static void msg_multi_mode(IRC_CHANNEL_REC *channel, const char *sender,
signal_add("print starting", (SIGNAL_FUNC) sig_print_starting);
rec = mode_find_channel(channel);
if (rec != NULL && strcmp(rec->mode, mode) != 0) {
if (rec != NULL && g_strcmp0(rec->mode, mode) != 0) {
/* different mode than last time, show and remove the old */
print_mode(rec);
mode_destroy(rec);

View file

@ -134,8 +134,8 @@ static void event_whois_realhost(IRC_SERVER_REC *server, const char *data)
/* <yournick> real hostname <nick> <hostname> */
params = event_get_params(data, 5, NULL, &nick, &txt_real,
&txt_hostname, &hostname);
if (strcmp(txt_real, "real") != 0 ||
strcmp(txt_hostname, "hostname") != 0) {
if (g_strcmp0(txt_real, "real") != 0 ||
g_strcmp0(txt_hostname, "hostname") != 0) {
/* <yournick> <nick> :... from <hostname> */
g_free(params);
params = event_get_params(data, 3, NULL, &nick, &hostname);
@ -219,7 +219,7 @@ static void event_whois_usermode(IRC_SERVER_REC *server, const char *data)
params = event_get_params(data, 4, NULL, &txt_usermodes,
&nick, &usermode);
if (strcmp(txt_usermodes, "usermodes") == 0) {
if (g_strcmp0(txt_usermodes, "usermodes") == 0) {
/* <yournick> usermodes <nick> usermode */
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_USERMODE, nick, usermode);