Merge pull request #235 from dequis/g_strcmp0

Change all strcmp() to g_strcmp0() to handle nulls gracefully
This commit is contained in:
Alexander Færøy 2015-04-17 21:13:18 +02:00
commit 03be2861dc
58 changed files with 174 additions and 170 deletions

View file

@ -167,7 +167,7 @@ static GSList *servers_find_chatnet_except(SERVER_REC *server)
SERVER_REC *rec = tmp->data;
if (server != rec && rec->connrec->chatnet != NULL &&
strcmp(server->connrec->chatnet,
g_strcmp0(server->connrec->chatnet,
rec->connrec->chatnet) == 0) {
/* chatnets match */
list = g_slist_append(list, rec);

View file

@ -58,7 +58,7 @@ static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr,
return NULL;
}
if (strcmp(password, "-") == 0)
if (g_strcmp0(password, "-") == 0)
*password = '\0';
/* check if -<chatnet> option is used to specify chat protocol */
@ -287,7 +287,7 @@ static void cmd_disconnect(const char *data, SERVER_REC *server)
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg))
return;
if (*tag != '\0' && strcmp(tag, "*") != 0) {
if (*tag != '\0' && g_strcmp0(tag, "*") != 0) {
server = server_find_tag(tag);
if (server == NULL)
server = server_find_lookup_tag(tag);
@ -347,7 +347,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
origtarget = target;
free_ret = FALSE;
if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) {
if (g_strcmp0(target, ",") == 0 || g_strcmp0(target, ".") == 0) {
target = parse_special(&target, server, item,
NULL, &free_ret, NULL, 0);
if (target != NULL && *target == '\0') {
@ -359,7 +359,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
}
if (target != NULL) {
if (strcmp(target, "*") == 0) {
if (g_strcmp0(target, "*") == 0) {
/* send to active channel/query */
if (item == NULL)
cmd_param_error(CMDERR_NOT_JOINED);

View file

@ -674,7 +674,7 @@ get_optional_channel(WI_ITEM_REC *active_item, char **data, int require_name)
origtmp = tmp = g_strdup(*data);
channel = cmd_get_param(&tmp);
if (strcmp(channel, "*") == 0 && !require_name) {
if (g_strcmp0(channel, "*") == 0 && !require_name) {
/* "*" means active channel */
cmd_get_param(data);
ret = window_item_get_target(active_item);

View file

@ -201,10 +201,10 @@ IGNORE_REC *ignore_find_noact(const char *servertag, const char *mask,
char **chan;
int ignore_servertag;
if (mask != NULL && (*mask == '\0' || strcmp(mask, "*") == 0))
if (mask != NULL && (*mask == '\0' || g_strcmp0(mask, "*") == 0))
mask = NULL;
ignore_servertag = servertag != NULL && strcmp(servertag, "*") == 0;
ignore_servertag = servertag != NULL && g_strcmp0(servertag, "*") == 0;
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
IGNORE_REC *rec = tmp->data;
@ -232,7 +232,7 @@ IGNORE_REC *ignore_find_noact(const char *servertag, const char *mask,
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)

View file

@ -54,7 +54,7 @@ int level_get(const char *level)
{
int n, len, match;
if (g_ascii_strcasecmp(level, "ALL") == 0 || strcmp(level, "*") == 0)
if (g_ascii_strcasecmp(level, "ALL") == 0 || g_strcmp0(level, "*") == 0)
return MSGLEVEL_ALL;
if (g_ascii_strcasecmp(level, "NEVER") == 0)
@ -177,7 +177,7 @@ int combine_level(int dest, const char *src)
itemname = *item + (**item == '+' || **item == '-' ? 1 : 0);
itemlevel = level_get(itemname);
if (strcmp(itemname, "NONE") == 0)
if (g_strcmp0(itemname, "NONE") == 0)
dest = 0;
else if (**item == '-')
dest &= ~(itemlevel);

View file

@ -110,7 +110,7 @@ int log_start_logging(LOG_REC *log)
log->real_fname = log_filename(log);
if (log->real_fname != NULL &&
strcmp(log->real_fname, log->fname) != 0) {
g_strcmp0(log->real_fname, log->fname) != 0) {
/* path may contain variables (%time, $vars),
make sure the directory is created */
dir = g_path_get_dirname(log->real_fname);
@ -181,7 +181,7 @@ static void log_rotate_check(LOG_REC *log)
return;
new_fname = log_filename(log);
if (strcmp(new_fname, log->real_fname) != 0) {
if (g_strcmp0(new_fname, log->real_fname) != 0) {
/* rotate log */
log_stop_logging(log);
signal_emit("log rotated", 1, log);
@ -245,7 +245,7 @@ static int itemcmp(const char *patt, const char *item)
{
/* returns 0 on match, nonzero otherwise */
if (!strcmp(patt, "*"))
if (!g_strcmp0(patt, "*"))
return 0;
return item ? g_ascii_strcasecmp(patt, item) : 1;
}
@ -320,7 +320,7 @@ LOG_REC *log_find(const char *fname)
for (tmp = logs; tmp != NULL; tmp = tmp->next) {
LOG_REC *rec = tmp->data;
if (strcmp(rec->fname, fname) == 0)
if (g_strcmp0(rec->fname, fname) == 0)
return rec;
}

View file

@ -184,7 +184,7 @@ int strarray_find(char **array, const char *item)
GSList *gslist_find_string(GSList *list, const char *key)
{
for (; list != NULL; list = list->next)
if (strcmp(list->data, key) == 0) return list;
if (g_strcmp0(list->data, key) == 0) return list;
return NULL;
}
@ -269,7 +269,7 @@ GSList *hashtable_get_keys(GHashTable *hash)
GList *glist_find_string(GList *list, const char *key)
{
for (; list != NULL; list = list->next)
if (strcmp(list->data, key) == 0) return list;
if (g_strcmp0(list->data, key) == 0) return list;
return NULL;
}

View file

@ -78,7 +78,7 @@ static char *module_get_root(const char *name, char **prefixes)
/* skip the _core part */
len = strlen(name);
if (len > 5 && strcmp(name+len-5, "_core") == 0)
if (len > 5 && g_strcmp0(name+len-5, "_core") == 0)
return g_strndup(name, len-5);
return g_strdup(name);
@ -94,11 +94,11 @@ static char *module_get_sub(const char *name, const char *root)
g_return_val_if_fail(namelen >= rootlen, g_strdup(name));
if (strncmp(name, root, rootlen) == 0 &&
strcmp(name+rootlen, "_core") == 0)
g_strcmp0(name+rootlen, "_core") == 0)
return g_strdup("core");
if (namelen > rootlen && name[namelen-rootlen-1] == '_' &&
strcmp(name+namelen-rootlen, root) == 0)
g_strcmp0(name+namelen-rootlen, root) == 0)
return g_strndup(name, namelen-rootlen-1);
return g_strdup(name);
@ -140,10 +140,10 @@ static GModule *module_open(const char *name, int *found)
static char *module_get_func(const char *rootmodule, const char *submodule,
const char *function)
{
if (strcmp(submodule, "core") == 0)
if (g_strcmp0(submodule, "core") == 0)
return g_strconcat(rootmodule, "_core_", function, NULL);
if (strcmp(rootmodule, submodule) == 0)
if (g_strcmp0(rootmodule, submodule) == 0)
return g_strconcat(rootmodule, "_", function, NULL);
return g_strconcat(submodule, "_", rootmodule, "_", function, NULL);
@ -200,7 +200,7 @@ static int module_load_name(const char *path, const char *rootmodule,
module = module_find(rootmodule);
rec = module == NULL ? NULL :
strcmp(rootmodule, submodule) == 0 ?
g_strcmp0(rootmodule, submodule) == 0 ?
module_file_find(module, "core") :
module_file_find(module, submodule);
if (rec == NULL) {
@ -277,7 +277,7 @@ static int module_load_full(const char *path, const char *rootmodule,
return FALSE;
module = module_find(rootmodule);
if (module != NULL && (strcmp(submodule, rootmodule) == 0 ||
if (module != NULL && (g_strcmp0(submodule, rootmodule) == 0 ||
module_file_find(module, submodule) != NULL)) {
/* module is already loaded */
module_error(MODULE_ERROR_ALREADY_LOADED, NULL,
@ -286,7 +286,7 @@ static int module_load_full(const char *path, const char *rootmodule,
}
/* check if the given module exists.. */
try_prefixes = strcmp(rootmodule, submodule) == 0;
try_prefixes = g_strcmp0(rootmodule, submodule) == 0;
status = module_load_name(path, rootmodule, submodule, try_prefixes);
if (status == -1 && try_prefixes) {
/* nope, try loading the module_core,
@ -340,7 +340,7 @@ int module_load_sub(const char *path, const char *submodule, char **prefixes)
g_free(name);
full_path = g_string_new(exppath);
if (strcmp(submodule, "core") == 0)
if (g_strcmp0(submodule, "core") == 0)
g_string_insert(full_path, end, "_core");
else {
g_string_insert_c(full_path, start, '_');

View file

@ -44,7 +44,7 @@ void *module_check_cast_module(void *object, int type_pos,
str = module_find_id_str(module,
G_STRUCT_MEMBER(int, object, type_pos));
return str == NULL || strcmp(str, id) != 0 ? NULL : object;
return str == NULL || g_strcmp0(str, id) != 0 ? NULL : object;
}
/* return unique number across all modules for `id' */
@ -251,7 +251,7 @@ MODULE_FILE_REC *module_file_find(MODULE_REC *module, const char *name)
for (tmp = module->files; tmp != NULL; tmp = tmp->next) {
MODULE_FILE_REC *rec = tmp->data;
if (strcmp(rec->name, name) == 0)
if (g_strcmp0(rec->name, name) == 0)
return rec;
}

View file

@ -478,7 +478,7 @@ static NICK_REC *nick_nfind(CHANNEL_REC *channel, const char *nick, int len)
if (rec != NULL) {
/* if there's multiple, get the one with identical case */
while (rec->next != NULL) {
if (strcmp(rec->nick, tmpnick) == 0)
if (g_strcmp0(rec->nick, tmpnick) == 0)
break;
rec = rec->next;
}

View file

@ -385,7 +385,7 @@ static void cmd_reconnect(const char *data, SERVER_REC *server)
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg))
return;
if (*tag != '\0' && strcmp(tag, "*") != 0)
if (*tag != '\0' && g_strcmp0(tag, "*") != 0)
server = server_find_tag(tag);
if (server != NULL) {

View file

@ -531,7 +531,7 @@ static void read_servers(void)
static void read_settings(void)
{
if (old_source_host == NULL ||
strcmp(old_source_host, settings_get_str("hostname")) != 0) {
g_strcmp0(old_source_host, settings_get_str("hostname")) != 0) {
g_free_not_null(old_source_host);
old_source_host = g_strdup(settings_get_str("hostname"));

View file

@ -295,7 +295,7 @@ void settings_remove(const char *key)
static int settings_remove_hash(const char *key, SETTINGS_REC *rec,
const char *module)
{
if (strcmp(rec->module, module) == 0) {
if (g_strcmp0(rec->module, module) == 0) {
settings_unref(rec, FALSE);
return TRUE;
}
@ -428,7 +428,7 @@ static void settings_clean_invalid_module(const char *module)
next = config_node_next(tmp);
set = g_hash_table_lookup(settings, subnode->key);
if (set == NULL || strcmp(set->module, module) != 0)
if (set == NULL || g_strcmp0(set->module, module) != 0)
iconfig_node_remove(node, subnode);
}
}
@ -458,7 +458,7 @@ static int backwards_compatibility(const char *module, CONFIG_NODE *node,
new_value = NULL; new_key = NULL; new_module = NULL;
/* fe-text term_type -> fe-common/core term_charset - for 0.8.10-> */
if (strcmp(module, "fe-text") == 0) {
if (g_strcmp0(module, "fe-text") == 0) {
if (g_ascii_strcasecmp(node->key, "term_type") == 0 ||
/* kludge for cvs-version where term_charset was in fe-text */
g_ascii_strcasecmp(node->key, "term_charset") == 0) {
@ -520,7 +520,7 @@ void settings_check_module(const char *module)
if (backwards_compatibility(module, node, parent))
continue;
if (set == NULL || strcmp(set->module, module) != 0) {
if (set == NULL || g_strcmp0(set->module, module) != 0) {
g_string_append_printf(errors, " %s", node->key);
count++;
}
@ -548,9 +548,9 @@ void settings_check_module(const char *module)
static int settings_compare(SETTINGS_REC *v1, SETTINGS_REC *v2)
{
int cmp = strcmp(v1->section, v2->section);
int cmp = g_strcmp0(v1->section, v2->section);
if (!cmp)
cmp = strcmp(v1->key, v2->key);
cmp = g_strcmp0(v1->key, v2->key);
return cmp;
}