From f14199d9c15a8062b5663fa6fcdae00390473b15 Mon Sep 17 00:00:00 2001 From: dequis Date: Tue, 7 Apr 2015 22:39:05 -0300 Subject: 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 --- src/perl/perl-core.c | 6 +++--- src/perl/perl-fe.c | 2 +- src/perl/perl-signals.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src/perl') diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c index eb1bddee..793f9375 100644 --- a/src/perl/perl-core.c +++ b/src/perl/perl-core.c @@ -44,7 +44,7 @@ static int print_script_errors; static char *perl_args[] = {"", "-e", "0"}; #define IS_PERL_SCRIPT(file) \ - (strlen(file) > 3 && strcmp(file+strlen(file)-3, ".pl") == 0) + (strlen(file) > 3 && g_strcmp0(file+strlen(file)-3, ".pl") == 0) static void perl_script_destroy_package(PERL_SCRIPT_REC *script) { @@ -314,7 +314,7 @@ PERL_SCRIPT_REC *perl_script_find(const char *name) for (tmp = perl_scripts; tmp != NULL; tmp = tmp->next) { PERL_SCRIPT_REC *rec = tmp->data; - if (strcmp(rec->name, name) == 0) + if (g_strcmp0(rec->name, name) == 0) return rec; } @@ -331,7 +331,7 @@ PERL_SCRIPT_REC *perl_script_find_package(const char *package) for (tmp = perl_scripts; tmp != NULL; tmp = tmp->next) { PERL_SCRIPT_REC *rec = tmp->data; - if (strcmp(rec->package, package) == 0) + if (g_strcmp0(rec->package, package) == 0) return rec; } diff --git a/src/perl/perl-fe.c b/src/perl/perl-fe.c index 8e8469e9..2abc75c0 100644 --- a/src/perl/perl-fe.c +++ b/src/perl/perl-fe.c @@ -170,7 +170,7 @@ static void cmd_load(const char *data, SERVER_REC *server, void *item) return; len = strlen(rootmodule); - if (len > 3 && strcmp(rootmodule + len - 3, ".pl") == 0) { + if (len > 3 && g_strcmp0(rootmodule + len - 3, ".pl") == 0) { /* make /LOAD script.pl work as expected */ signal_stop(); cmd_script_load(data); diff --git a/src/perl/perl-signals.c b/src/perl/perl-signals.c index 1f602c66..007f7ad5 100644 --- a/src/perl/perl-signals.c +++ b/src/perl/perl-signals.c @@ -99,14 +99,14 @@ void perl_signal_args_to_c( if (!SvOK(arg)) { c_arg = NULL; - } else if (strcmp(rec->args[n], "string") == 0) { + } else if (g_strcmp0(rec->args[n], "string") == 0) { c_arg = SvPV_nolen(arg); - } else if (strcmp(rec->args[n], "int") == 0) { + } else if (g_strcmp0(rec->args[n], "int") == 0) { c_arg = (void *)SvIV(arg); - } else if (strcmp(rec->args[n], "ulongptr") == 0) { + } else if (g_strcmp0(rec->args[n], "ulongptr") == 0) { saved_args[n].v_ulong = SvUV(arg); c_arg = &saved_args[n].v_ulong; - } else if (strcmp(rec->args[n], "intptr") == 0) { + } else if (g_strcmp0(rec->args[n], "intptr") == 0) { saved_args[n].v_int = SvIV(SvRV(arg)); c_arg = &saved_args[n].v_int; } else if (strncmp(rec->args[n], "glistptr_", 9) == 0) { @@ -122,7 +122,7 @@ void perl_signal_args_to_c( } av = (AV *)t; - is_str = strcmp(rec->args[n]+9, "char*") == 0; + is_str = g_strcmp0(rec->args[n]+9, "char*") == 0; gl = NULL; count = av_len(av) + 1; @@ -181,7 +181,7 @@ void perl_signal_args_to_c( continue; } - if (strcmp(rec->args[n], "intptr") == 0) { + if (g_strcmp0(rec->args[n], "intptr") == 0) { SV *t = SvRV(arg); SvIOK_only(t); SvIV_set(t, saved_args[n].v_int); @@ -192,8 +192,8 @@ void perl_signal_args_to_c( AV *av; GList *gl, *tmp; - is_iobject = strcmp(rec->args[n]+9, "iobject") == 0; - is_str = strcmp(rec->args[n]+9, "char*") == 0; + is_iobject = g_strcmp0(rec->args[n]+9, "iobject") == 0; + is_str = g_strcmp0(rec->args[n]+9, "char*") == 0; av = (AV *)SvRV(arg); av_clear(av); @@ -245,8 +245,8 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func, GList *tmp, **ptr; int is_iobject, is_str; - is_iobject = strcmp(rec->args[n]+9, "iobject") == 0; - is_str = strcmp(rec->args[n]+9, "char*") == 0; + is_iobject = g_strcmp0(rec->args[n]+9, "iobject") == 0; + is_str = g_strcmp0(rec->args[n]+9, "char*") == 0; av = newAV(); ptr = arg; @@ -258,22 +258,22 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func, } saved_args[n] = perlarg = newRV_noinc((SV *) av); - } else if (strcmp(rec->args[n], "int") == 0) + } else if (g_strcmp0(rec->args[n], "int") == 0) perlarg = newSViv((IV)arg); else if (arg == NULL) perlarg = &PL_sv_undef; - else if (strcmp(rec->args[n], "string") == 0) + else if (g_strcmp0(rec->args[n], "string") == 0) perlarg = new_pv(arg); - else if (strcmp(rec->args[n], "ulongptr") == 0) + else if (g_strcmp0(rec->args[n], "ulongptr") == 0) perlarg = newSViv(*(unsigned long *) arg); - else if (strcmp(rec->args[n], "intptr") == 0) + else if (g_strcmp0(rec->args[n], "intptr") == 0) saved_args[n] = perlarg = newRV_noinc(newSViv(*(int *) arg)); else if (strncmp(rec->args[n], "gslist_", 7) == 0) { /* linked list - push as AV */ GSList *tmp; int is_iobject; - is_iobject = strcmp(rec->args[n]+7, "iobject") == 0; + is_iobject = g_strcmp0(rec->args[n]+7, "iobject") == 0; av = newAV(); for (tmp = arg; tmp != NULL; tmp = tmp->next) { sv = is_iobject ? iobject_bless((SERVER_REC *) tmp->data) : @@ -282,12 +282,12 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func, } perlarg = newRV_noinc((SV *) av); - } else if (strcmp(rec->args[n], "iobject") == 0) { + } else if (g_strcmp0(rec->args[n], "iobject") == 0) { /* "irssi object" - any struct that has "int type; int chat_type" as it's first variables (server, channel, ..) */ perlarg = iobject_bless((SERVER_REC *) arg); - } else if (strcmp(rec->args[n], "siobject") == 0) { + } else if (g_strcmp0(rec->args[n], "siobject") == 0) { /* "simple irssi object" - any struct that has int type; as it's first variable (dcc) */ perlarg = simple_iobject_bless((SERVER_REC *) arg); @@ -317,7 +317,7 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func, if (saved_args[n] == NULL) continue; - if (strcmp(rec->args[n], "intptr") == 0) { + if (g_strcmp0(rec->args[n], "intptr") == 0) { int *val = arg; *val = SvIV(SvRV(saved_args[n])); } else if (strncmp(rec->args[n], "glistptr_", 9) == 0) { @@ -338,7 +338,7 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func, out = g_list_append(out, val); } - if (strcmp(rec->args[n]+9, "char*") == 0) + if (g_strcmp0(rec->args[n]+9, "char*") == 0) g_list_foreach(*ret, (GFunc) g_free, NULL); g_list_free(*ret); *ret = out; @@ -434,7 +434,7 @@ static void perl_signal_remove_list_one(GSList **siglist, PERL_SIGNAL_REC *rec) #define sv_func_cmp(f1, f2) \ (f1 == f2 || (SvPOK(f1) && SvPOK(f2) && \ - strcmp(SvPV_nolen(f1), SvPV_nolen(f2)) == 0)) + g_strcmp0(SvPV_nolen(f1), SvPV_nolen(f2)) == 0)) static void perl_signal_remove_list(GSList **list, SV *func) { -- cgit v1.2.3