From 76f9452985b3b5a553bdb0d9e0fa9c439ecd16c5 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Sat, 21 Aug 2010 13:52:25 +0000 Subject: [PATCH] Convert (hopefully) all comparisons to NULL Apply badzero.cocci, badnull.coci and badnull2.cocci This should convert all cases where there's a comparison to NULL to simpler forms. This patch applies the following transformations: code before patch ||code after patch =============================================================== return a == NULL; return !a; return a != NULL; return !!a; func(a == NULL); func(!a); func(a != NULL); func(!!a); b = a == NULL; b = !a; b = a != NULL; b = !!a; b = a == NULL ? c : d; b = !a ? c : d; b = a != NULL ? c : d; b = a ? c : d; other cases: a == NULL !a a != NULL a SVN revision: 51487 --- src/bin/test_panel.c | 4 ++-- src/lib/elc_fileselector.c | 2 +- src/lib/elm_label.c | 32 ++++++++++++++++---------------- src/lib/elm_list.c | 2 +- src/lib/elm_main.c | 4 ++-- src/lib/elm_win.c | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/bin/test_panel.c b/src/bin/test_panel.c index 63a70f576..7320bb603 100644 --- a/src/bin/test_panel.c +++ b/src/bin/test_panel.c @@ -82,7 +82,7 @@ _fill_list(Evas_Object *obj) char *real; if (!(d = opendir(getenv("HOME")))) return; - while ((de = readdir(d)) != NULL) + while ((de = readdir(d))) { char buff[PATH_MAX]; @@ -122,7 +122,7 @@ _dir_has_subs(const char *path) if (!path) return result; if (!(d = opendir(path))) return result; - while ((de = readdir(d)) != NULL) + while ((de = readdir(d))) { char buff[PATH_MAX]; diff --git a/src/lib/elc_fileselector.c b/src/lib/elc_fileselector.c index fceded7b6..8eed9617b 100644 --- a/src/lib/elc_fileselector.c +++ b/src/lib/elc_fileselector.c @@ -342,7 +342,7 @@ _populate(Evas_Object *obj, const char *path, Elm_Genlist_Item *parent) } if (wd->entry2) elm_entry_entry_set(wd->entry2, ""); - while ((dp = readdir(dir)) != NULL) + while ((dp = readdir(dir))) { if (dp->d_name[0] == '.') continue; // TODO make this configurable diff --git a/src/lib/elm_label.c b/src/lib/elm_label.c index a7161b83a..a858c7708 100644 --- a/src/lib/elm_label.c +++ b/src/lib/elm_label.c @@ -139,7 +139,7 @@ _get_value_in_key_string(const char *oldstring, char *key, char **value) { starttag = curlocater; endtag = curlocater + strlen(key); - if ((endtag == NULL) || (*endtag != '=')) + if ((!endtag) || (*endtag != '=')) { foundflag = 0; return -1; @@ -160,10 +160,10 @@ _get_value_in_key_string(const char *oldstring, char *key, char **value) break; else starttag--; - if (starttag == NULL) break; + if (!starttag) break; } - while (NULL != endtag) + while (endtag) { if (*endtag == '<') { @@ -174,7 +174,7 @@ _get_value_in_key_string(const char *oldstring, char *key, char **value) break; else endtag++; - if (endtag == NULL) break; + if (!endtag) break; } if ((foundflag != 0) && (*starttag == '<') && (*endtag == '>')) @@ -205,7 +205,7 @@ _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int srcstring = eina_strbuf_string_get(srcbuf); curlocater = strstr(srcstring, key); - if (curlocater == NULL) + if (!curlocater) insertflag = 1; else { @@ -216,7 +216,7 @@ _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int tagtxtlen = endtag - starttag; if (tagtxtlen <= 0) tagtxtlen = 0; if ((starttag < curlocater) && (curlocater < endtag)) break; - if ((endtag != NULL) && ((endtag + 1) != NULL)) + if ((endtag) && ((endtag + 1))) srcstring = endtag + 1; else break; @@ -229,20 +229,20 @@ _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int eina_strbuf_append_n(repbuf, starttag, tagtxtlen); srcstring = eina_strbuf_string_get(repbuf); curlocater = strstr(srcstring, key); - if (curlocater != NULL) + if (curlocater) { replocater = curlocater + strlen(key) + 1; - while ((*replocater != '=') && (replocater != NULL)) + while ((*replocater != '=') && (replocater)) replocater++; - if (replocater != NULL) + if (replocater) { replocater++; while ((*replocater != ' ') && (*replocater != '>') && - (replocater == NULL)) + (!replocater)) replocater++; } - if (replocater != NULL) + if (replocater) { replocater--; eina_strbuf_append_n(diffbuf, curlocater, @@ -259,8 +259,8 @@ _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int insertflag = 1; } - if (repbuf == NULL) repbuf = eina_strbuf_new(); - if (diffbuf == NULL) diffbuf = eina_strbuf_new(); + if (!repbuf) repbuf = eina_strbuf_new(); + if (!diffbuf) diffbuf = eina_strbuf_new(); if (insertflag) { @@ -351,7 +351,7 @@ _ellipsis_label_to_width(Evas_Object *obj) if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0) { - if (kvalue != NULL) cur_fontsize = atoi((char *)kvalue); + if (kvalue) cur_fontsize = atoi((char *)kvalue); } txtbuf = eina_strbuf_new(); @@ -362,7 +362,7 @@ _ellipsis_label_to_width(Evas_Object *obj) if (cur_fontsize > minfontsize) { cur_fontsize--; - if (fontbuf != NULL) + if (fontbuf) { eina_strbuf_free(fontbuf); fontbuf = NULL; @@ -376,7 +376,7 @@ _ellipsis_label_to_width(Evas_Object *obj) } else { - if (txtbuf != NULL) + if (txtbuf) { eina_strbuf_free(txtbuf); txtbuf = NULL; diff --git a/src/lib/elm_list.c b/src/lib/elm_list.c index fd41a283f..a263ba6bd 100644 --- a/src/lib/elm_list.c +++ b/src/lib/elm_list.c @@ -249,7 +249,7 @@ _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info) Elm_List_Item *it; if (!wd) return; - if (sub == NULL) abort(); + if (!sub) abort(); if (sub == wd->scr) wd->scr = NULL; else diff --git a/src/lib/elm_main.c b/src/lib/elm_main.c index b07dd5bb3..9278c03cc 100644 --- a/src/lib/elm_main.c +++ b/src/lib/elm_main.c @@ -715,7 +715,7 @@ save_env(void) oldenv = environ; - for (i = 0, size = 0; environ[i] != NULL; i++) + for (i = 0, size = 0; environ[i]; i++) size += strlen(environ[i]) + 1; p = malloc((i + 1) * sizeof(char *)); @@ -723,7 +723,7 @@ save_env(void) environ = p; - for (i = 0; oldenv[i] != NULL; i++) + for (i = 0; oldenv[i]; i++) environ[i] = strdup(oldenv[i]); environ[i] = NULL; } diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c index 3163932d8..8bf774d7f 100644 --- a/src/lib/elm_win.c +++ b/src/lib/elm_win.c @@ -130,12 +130,12 @@ _elm_win_obj_callback_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void ecore_evas_callback_resize_set(win->ee, NULL); if (win->deferred_resize_job) ecore_job_del(win->deferred_resize_job); if (win->deferred_child_eval_job) ecore_job_del(win->deferred_child_eval_job); - while (((child = evas_object_bottom_get(win->evas)) != NULL) && + while (((child = evas_object_bottom_get(win->evas))) && (child != obj)) { evas_object_del(child); } - while (((child = evas_object_top_get(win->evas)) != NULL) && + while (((child = evas_object_top_get(win->evas))) && (child != obj)) { evas_object_del(child); -- 2.34.1