Convert (hopefully) all comparisons to NULL
authorlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 21 Aug 2010 13:52:25 +0000 (13:52 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 21 Aug 2010 13:52:25 +0000 (13:52 +0000)
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

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eet@51487 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eet_cipher.c
src/lib/eet_data.c
src/lib/eet_dictionary.c
src/lib/eet_image.c
src/lib/eet_lib.c
src/lib/eet_node.c
src/tests/eet_suite.c

index 7821759..4b44143 100644 (file)
@@ -426,7 +426,7 @@ on_error:
 void
 eet_identity_ref(Eet_Key *key)
 {
-   if (key == NULL)
+   if (!key)
       return;
 
    key->references++;
@@ -435,7 +435,7 @@ eet_identity_ref(Eet_Key *key)
 void
 eet_identity_unref(Eet_Key *key)
 {
-   if (key == NULL)
+   if (!key)
       return;
 
    key->references--;
@@ -573,7 +573,7 @@ eet_identity_sign(FILE    *fp,
 # else /* ifdef HAVE_GNUTLS */
    sign_len = EVP_PKEY_size(key->private_key);
    sign = malloc(sign_len);
-   if (sign == NULL)
+   if (!sign)
      {
         err = EET_ERROR_OUT_OF_MEMORY;
         goto on_error;
@@ -717,7 +717,7 @@ eet_identity_check(const void   *data_base,
    gcry_md_write(md, data_base, data_length);
 
    hash = gcry_md_read(md, GCRY_MD_SHA1);
-   if (hash == NULL)
+   if (!hash)
      {
         gcry_md_close(md);
         return NULL;
@@ -773,12 +773,12 @@ eet_identity_check(const void   *data_base,
    tmp = alloca(cert_len);
    memcpy((char *)tmp, cert_der, cert_len);
    x509 = d2i_X509(NULL, &tmp, cert_len);
-   if (x509 == NULL)
+   if (!x509)
       return NULL;
 
    /* Get public key - eay */
    pkey = X509_get_pubkey(x509);
-   if (pkey == NULL)
+   if (!pkey)
      {
         X509_free(x509);
         return NULL;
@@ -864,7 +864,7 @@ on_error:
    tmp = alloca(der_length);
    memcpy((char *)tmp, certificate, der_length);
    x509 = d2i_X509(NULL, &tmp, der_length);
-   if (x509 == NULL)
+   if (!x509)
      {
         INF("Not a valid certificate.");
         return;
@@ -1236,7 +1236,7 @@ eet_hmac_sha1(const void    *key,
    gcry_md_write(mdh, data, data_len);
 
    hash = gcry_md_read(mdh, GCRY_MD_SHA1);
-   if (hash == NULL)
+   if (!hash)
      {
         gcry_md_close(mdh);
         return 1;
index 995d55b..2ae5246 100644 (file)
@@ -727,7 +727,7 @@ eet_data_get_string(const Eet_Dictionary *ed,
            return -1;
 
         str = eet_dictionary_string_get_char(ed, idx);
-        if (str == NULL)
+        if (!str)
            return -1;
 
         *d = (char *)str;
@@ -735,7 +735,7 @@ eet_data_get_string(const Eet_Dictionary *ed,
      }
 
    s = (char *)src;
-   if (s == NULL)
+   if (!s)
      {
         *d = NULL;
         return 0;
@@ -1873,7 +1873,7 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
         || group_type == EET_G_VARIANT)
        &&
        (type != EET_T_UNKNOW
-        || subtype == NULL
+        || !subtype
         || subtype->func.type_get == NULL
         || subtype->func.type_set == NULL))
       return;
@@ -1918,7 +1918,7 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
        && (group_type < EET_G_LAST)
        && (((type > EET_T_UNKNOW) && (type < EET_T_STRING))
            || ((type > EET_T_NULL) && (type < EET_T_LAST)))
-       && (subtype == NULL))
+       && (!subtype))
      {
         subtype = calloc(1, sizeof (Eet_Data_Descriptor));
         if (!subtype)
@@ -2522,7 +2522,7 @@ _eet_data_dump_encode(int             parent_type,
            _eet_data_words_bigendian = 0;
      }
 
-   if (node == NULL)
+   if (!node)
       return NULL;
 
    ds = eet_data_stream_new();
@@ -4123,7 +4123,7 @@ eet_data_get_unknown(Eet_Free_Context     *context,
                   str = (char **)(((char *)data));
                   if (*str)
                     {
-                       if ((ed == NULL) || (edd->func.str_direct_alloc == NULL))
+                       if ((!ed) || (edd->func.str_direct_alloc == NULL))
                          {
                             *str = edd->func.str_alloc(*str);
                             _eet_freelist_str_add(context, *str);
index 7e86d08..23ef3b0 100644 (file)
@@ -110,7 +110,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
         total = ed->total + 8;
 
         new = realloc(ed->all, sizeof (Eet_String) * total);
-        if (new == NULL)
+        if (!new)
            return -1;
 
         ed->all = new;
@@ -119,7 +119,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
 
    len = strlen(string) + 1;
    str = strdup(string);
-   if (str == NULL)
+   if (!str)
       return -1;
 
    current = ed->all + ed->count;
@@ -201,7 +201,7 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed,
      {
 #ifdef _WIN32
         /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
-        if (ed->all[idx].str == NULL)
+        if (!ed->all[idx].str)
           {
              ed->all[idx].str = strdup(ed->all[idx].mmap);
              ed->all[idx].mmap = NULL;
@@ -397,7 +397,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed,
 {
    int i;
 
-   if ((ed == NULL) || (string == NULL))
+   if ((!ed) || (!string))
       return 0;
 
    if ((ed->start <= string) && (string < ed->end))
index 9c52dfd..446ec3d 100644 (file)
@@ -146,7 +146,7 @@ _eet_jpeg_membuf_dst_flush(j_compress_ptr cinfo)
    unsigned char *buf;
 
    if (dst->len >= 0x40000000 ||
-       (buf = realloc(dst->buf, dst->len * 2)) == NULL)
+       !(buf = realloc(dst->buf, dst->len * 2)))
      {
         dst->failed = 1;
         dst->pub.next_output_byte = dst->buf;
@@ -1279,7 +1279,7 @@ eet_data_image_encode_cipher(const void  *data,
 
         /* eet_data_image_lossless_compressed_convert will refuse to compress something
            if the result is bigger than the entry. */
-        if (comp <= 0 || d == NULL)
+        if (comp <= 0 || !d)
            d = eet_data_image_lossless_convert(&size, data, w, h, alpha);
      }
    else
index c1ca7fa..b736fc0 100644 (file)
@@ -1117,7 +1117,7 @@ eet_internal_read2(Eet_File *ef)
                                           &ef->signature_length,
                                           &ef->x509_length);
 
-        if (eet_test_close(ef->x509_der == NULL, ef))
+        if (eet_test_close(!ef->x509_der, ef))
            return NULL;
 
 #else /* ifdef HAVE_SIGNATURE */
@@ -1264,7 +1264,7 @@ eet_internal_read1(Eet_File *ef)
         if (efn->free_name)
           {
              efn->name = malloc(sizeof(char) * name_size + 1);
-             if (eet_test_close(efn->name == NULL, ef))
+             if (eet_test_close(!efn->name, ef))
                {
                   free(efn);
                   return NULL;
@@ -1318,7 +1318,7 @@ eet_internal_read(Eet_File *ef)
 {
    const int *data = (const int *)ef->data;
 
-   if (eet_test_close((ef->data == (void *)-1) || (ef->data == NULL), ef))
+   if (eet_test_close((ef->data == (void *)-1) || (!ef->data), ef))
       return NULL;
 
    if (eet_test_close(ef->data_size < (int)sizeof(int) * 3, ef))
@@ -1454,7 +1454,7 @@ eet_memopen_read(const void *data,
 {
    Eet_File *ef;
 
-   if (data == NULL || size == 0)
+   if (!data || size == 0)
       return NULL;
 
    ef = malloc (sizeof (Eet_File));
@@ -1552,7 +1552,7 @@ eet_open(const char   *file,
           }
 
 open_error:
-        if (fp == NULL && mode == EET_FILE_MODE_READ)
+        if (!fp && mode == EET_FILE_MODE_READ)
            goto on_error;
      }
    else
@@ -1579,7 +1579,7 @@ open_error:
    if (ef)
      {
         /* reference it up and return it */
-        if (fp != NULL)
+        if (fp)
            fclose(fp);
 
         ef->references++;
@@ -2385,7 +2385,7 @@ eet_delete(Eet_File   *ef,
              if (efn->data)
                 free(efn->data);
 
-             if (pefn == NULL)
+             if (!pefn)
                 ef->header->directory->nodes[hash] = efn->next;
              else
                 pefn->next = efn->next;
index fd4f07a..db1c58c 100644 (file)
@@ -606,7 +606,7 @@ eet_node_dump(Eet_Node *n,
               dumpfunc(dumpdata, "\";\n");
            }
 
-         for (it = n->values; it != NULL; it = it->next)
+         for (it = n->values; it; it = it->next)
             eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata);
 
          eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata);
@@ -653,7 +653,7 @@ eet_node_walk(void          *parent,
       case EET_G_UNKNOWN:
          me = cb->struct_alloc(root->name, user_data);
 
-         for (it = root->values; it != NULL; it = it->next)
+         for (it = root->values; it; it = it->next)
             eet_node_walk(me, it->name, it, cb, user_data);
 
          break;
@@ -663,7 +663,7 @@ eet_node_walk(void          *parent,
          me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
                         root->name, root->count, user_data);
 
-         for (i = 0, it = root->values; it != NULL; it = it->next)
+         for (i = 0, it = root->values; it; it = it->next)
             cb->insert(me, i++, eet_node_walk(NULL,
                                               NULL,
                                               it,
@@ -675,7 +675,7 @@ eet_node_walk(void          *parent,
       case EET_G_LIST:
          me = cb->list(root->name, user_data);
 
-         for (it = root->values; it != NULL; it = it->next)
+         for (it = root->values; it; it = it->next)
             cb->append(me, eet_node_walk(NULL,
                                          NULL,
                                          it,
index 9c4d5f0..408fcf5 100644 (file)
@@ -203,13 +203,13 @@ _eet_test_basic_check(Eet_Test_Basic_Type * result, int i)
 
    fail_if(tmp > 0.00005);
 
-   fail_if(result->empty != NULL);
+   fail_if(!!result->empty);
    if (i == 0)
      {
         Eet_Test_Basic_Type * tmp;
 
         tmp = result->with;
-        fail_if(tmp == NULL);
+        fail_if(!tmp);
 
         fail_if(tmp->c != EET_TEST_CHAR);
         fail_if(tmp->s != EET_TEST_SHORT);
@@ -223,7 +223,7 @@ _eet_test_basic_check(Eet_Test_Basic_Type * result, int i)
         fail_if(tmp->ul != EET_TEST_LONG_LONG);
      }
    else
-      fail_if(result->with != NULL);
+      fail_if(!!result->with);
 } /* _eet_test_basic_check */
 
 static void
@@ -895,7 +895,7 @@ START_TEST(eet_file_simple_write)
 
    fail_if(eet_mode_get(ef) != EET_FILE_MODE_WRITE);
 
-   fail_if(eet_list(ef, "*", &size) != NULL);
+   fail_if(!!eet_list(ef, "*", &size));
    fail_if(eet_num_entries(ef) != -1);
 
    eet_close(ef);
@@ -1036,11 +1036,11 @@ START_TEST(eet_file_data_test)
    /* Test the resulting data. */
    fail_if(_eet_test_ex_check(result, 0) != 0);
    fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
-   fail_if(eina_list_data_get(result->ilist) == NULL);
+   fail_if(!eina_list_data_get(result->ilist));
    fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
-   fail_if(eina_list_data_get(result->slist) == NULL);
+   fail_if(!eina_list_data_get(result->slist));
    fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
-   fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
+   fail_if(!eina_hash_find(result->shash, EET_TEST_KEY1));
    fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
    fail_if(strcmp(result->charray[0], "test") != 0);
 
@@ -1074,13 +1074,13 @@ START_TEST(eet_file_data_test)
    fail_if(eet_num_entries(ef) != 1);
 
    /* Test some more wrong case */
-   fail_if(eet_data_read(ef, edd, "plop") != NULL);
-   fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL);
+   fail_if(!!eet_data_read(ef, edd, "plop"));
+   fail_if(!!eet_data_read(ef, edd, EET_TEST_FILE_KEY1));
 
    /* Reinsert and reread data */
    fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
-   fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL);
-   fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL);
+   fail_if(!eet_data_read(ef, edd, EET_TEST_FILE_KEY1));
+   fail_if(!eet_read_direct(ef, EET_TEST_FILE_KEY1, &size));
 
    eet_close(ef);
 
@@ -1163,11 +1163,11 @@ START_TEST(eet_file_data_dump_test)
    /* Test the resulting data. */
    fail_if(_eet_test_ex_check(result, 0) != 0);
    fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
-   fail_if(eina_list_data_get(result->ilist) == NULL);
+   fail_if(!eina_list_data_get(result->ilist));
    fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
-   fail_if(eina_list_data_get(result->slist) == NULL);
+   fail_if(!eina_list_data_get(result->slist));
    fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
-   fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
+   fail_if(!eina_hash_find(result->shash, EET_TEST_KEY1));
    fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
    fail_if(strcmp(result->charray[0], "test") != 0);
 
@@ -1307,7 +1307,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_noalpha.w);
    fail_if(h != test_noalpha.h);
    fail_if(alpha != test_noalpha.alpha);
@@ -1353,7 +1353,7 @@ START_TEST(eet_image)
    fail_if(lossy != 0);
 
    data = malloc(w * h * 4);
-   fail_if(data == NULL);
+   fail_if(!data);
    result = eet_data_image_read_to_surface(ef,
                                            EET_TEST_FILE_IMAGE "0",
                                            4,
@@ -1375,7 +1375,7 @@ START_TEST(eet_image)
    free(data);
 
    data = malloc(w * h * 4);
-   fail_if(data == NULL);
+   fail_if(!data);
    result = eet_data_image_read_to_surface(ef,
                                            EET_TEST_FILE_IMAGE "0",
                                            0,
@@ -1404,7 +1404,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_noalpha.w);
    fail_if(h != test_noalpha.h);
    fail_if(alpha != test_noalpha.alpha);
@@ -1422,7 +1422,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_noalpha.w);
    fail_if(h != test_noalpha.h);
    fail_if(alpha != test_noalpha.alpha);
@@ -1439,7 +1439,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_noalpha.w);
    fail_if(h != test_noalpha.h);
    fail_if(alpha != test_noalpha.alpha);
@@ -1454,7 +1454,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_noalpha.w);
    fail_if(h != test_noalpha.h);
    fail_if(alpha != test_noalpha.alpha);
@@ -1469,7 +1469,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_noalpha.w);
    fail_if(h != test_noalpha.h);
    fail_if(alpha != test_noalpha.alpha);
@@ -1499,7 +1499,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_alpha.w);
    fail_if(h != test_alpha.h);
    fail_if(alpha != test_alpha.alpha);
@@ -1530,7 +1530,7 @@ START_TEST(eet_image)
                               &compress,
                               &quality,
                               &lossy);
-   fail_if(data == NULL);
+   fail_if(!data);
    fail_if(w != test_alpha.w);
    fail_if(h != test_alpha.h);
    fail_if(alpha != test_alpha.alpha);
@@ -1654,7 +1654,7 @@ START_TEST(eet_identity_simple)
    fail_if(memcmp(test, buffer, strlen(buffer) + 1) != 0);
 
    tmp = eet_identity_x509(ef, &size);
-   fail_if(tmp == NULL);
+   fail_if(!tmp);
 
    eet_identity_certificate_print(tmp, size, noread);
 
@@ -1850,7 +1850,7 @@ open_close_worker(void * path)
    while (!open_worker_stop)
      {
         Eet_File * ef = eet_open((char const *)path, EET_FILE_MODE_READ);
-        if (ef == NULL)
+        if (!ef)
            pthread_exit("eet_open() failed");
         else
           {
@@ -1871,7 +1871,7 @@ open_close_worker(void * path)
    while (!open_worker_stop)
      {
         Eet_File * ef = eet_open((char const *)path, EET_FILE_MODE_READ);
-        if (ef == NULL)
+        if (!ef)
            _endthreadex(-1);
         else
           {
@@ -1964,11 +1964,11 @@ _eet_connection_read(const void * eet_data, size_t size, void * user_data)
    fail_if(!node);
    fail_if(_eet_test_ex_check(result, 0) != 0);
    fail_if(_eet_test_ex_check(eina_list_data_get(result->list), 1) != 0);
-   fail_if(eina_list_data_get(result->ilist) == NULL);
+   fail_if(!eina_list_data_get(result->ilist));
    fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
-   fail_if(eina_list_data_get(result->slist) == NULL);
+   fail_if(!eina_list_data_get(result->slist));
    fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
-   fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
+   fail_if(!eina_hash_find(result->shash, EET_TEST_KEY1));
    fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
    fail_if(strcmp(result->charray[0], "test") != 0);
 
@@ -2329,7 +2329,7 @@ _eet_union_type_get(const void * data, Eina_Bool * unknow)
    if (unknow)
       *unknow = EINA_FALSE;
 
-   for (i = 0; eet_mapping[i].name != NULL; ++i)
+   for (i = 0; eet_mapping[i].name; ++i)
       if (*u == eet_mapping[i].u)
          return eet_mapping[i].name;
 
@@ -2348,7 +2348,7 @@ _eet_union_type_set(const char * type, void * data, Eina_Bool unknow)
    if (unknow)
       return EINA_FALSE;
 
-   for (i = 0; eet_mapping[i].name != NULL; ++i)
+   for (i = 0; eet_mapping[i].name; ++i)
       if (strcmp(eet_mapping[i].name, type) == 0)
         {
            *u = eet_mapping[i].u;
@@ -2367,7 +2367,7 @@ _eet_variant_type_get(const void * data, Eina_Bool * unknow)
    if (unknow)
       *unknow = type->unknow;
 
-   for (i = 0; eet_mapping[i].name != NULL; ++i)
+   for (i = 0; eet_mapping[i].name; ++i)
       if (strcmp(type->type, eet_mapping[i].name) == 0)
          return eet_mapping[i].name;