declare variables when you need them and when you can initialize them
authorRoker <roker@pep-project.org>
Thu, 14 Jul 2016 10:13:08 +0200
changeset 871f0c1582416e3
parent 870 12b107a600d3
child 873 b4a7faf689d2
child 874 c88b2d6f23cd
child 879 6460821c3170
child 883 096ff09932ad
declare variables when you need them and when you can initialize them
src/mime.c
     1.1 --- a/src/mime.c	Thu Jul 14 07:03:28 2016 +0200
     1.2 +++ b/src/mime.c	Thu Jul 14 10:13:08 2016 +0200
     1.3 @@ -888,10 +888,7 @@
     1.4  
     1.5  static pEp_identity *mailbox_to_identity(const struct mailimf_mailbox * mb)
     1.6  {
     1.7 -    pEp_identity *ident;
     1.8      char *username = NULL;
     1.9 -    size_t index;
    1.10 -    int r;
    1.11  
    1.12      assert(mb);
    1.13      assert(mb->mb_addr_spec);
    1.14 @@ -900,14 +897,14 @@
    1.15          return NULL;
    1.16  
    1.17      if (mb->mb_display_name) {
    1.18 -        index = 0;
    1.19 -        r = mailmime_encoded_phrase_parse("utf-8", mb->mb_display_name,
    1.20 +        size_t index = 0;
    1.21 +        const int r = mailmime_encoded_phrase_parse("utf-8", mb->mb_display_name,
    1.22                  strlen(mb->mb_display_name), &index, "utf-8", &username);
    1.23          if (r)
    1.24              goto enomem;
    1.25      }
    1.26  
    1.27 -    ident = new_identity(mb->mb_addr_spec, NULL, NULL, username);
    1.28 +    pEp_identity *ident = new_identity(mb->mb_addr_spec, NULL, NULL, username);
    1.29      if (ident == NULL)
    1.30          goto enomem;
    1.31      free(username);
    1.32 @@ -916,7 +913,6 @@
    1.33  
    1.34  enomem:
    1.35      free(username);
    1.36 -
    1.37      return NULL;
    1.38  }
    1.39  
    1.40 @@ -930,22 +926,18 @@
    1.41          const struct mailimf_address_list *mal
    1.42      )
    1.43  {
    1.44 -    identity_list *il = NULL;
    1.45 +    assert(mal);
    1.46      clist *list = mal->ad_list;
    1.47 -    struct mailimf_address * addr = NULL;
    1.48 -    clistiter *cur;
    1.49  
    1.50 -    assert(mal);
    1.51 -
    1.52 -    il = new_identity_list(NULL);
    1.53 +    identity_list *il = new_identity_list(NULL);
    1.54      if (il == NULL)
    1.55          goto enomem;
    1.56  
    1.57      identity_list *_il = il;
    1.58 -    for (cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
    1.59 +    for (clistiter *cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
    1.60          pEp_identity *ident;
    1.61  
    1.62 -        addr = clist_content(cur);
    1.63 +        struct mailimf_address *addr = clist_content(cur);
    1.64          switch(addr->ad_type) {
    1.65              case MAILIMF_ADDRESS_MAILBOX:
    1.66                  ident = mailbox_to_identity(addr->ad_data.ad_mailbox);
    1.67 @@ -958,10 +950,9 @@
    1.68  
    1.69              case MAILIMF_ADDRESS_GROUP:
    1.70                  {
    1.71 -                    clistiter *cur2;
    1.72                      struct mailimf_mailbox_list * mbl =
    1.73                              addr->ad_data.ad_group->grp_mb_list;
    1.74 -                    for (cur2 = clist_begin(mbl->mb_list); cur2 != NULL;
    1.75 +                    for (clistiter *cur2 = clist_begin(mbl->mb_list); cur2 != NULL;
    1.76                              cur2 = clist_next(cur2)) {
    1.77                          ident = mailbox_to_identity(clist_content(cur));
    1.78                          if (ident == NULL)
    1.79 @@ -983,7 +974,6 @@
    1.80  
    1.81  enomem:
    1.82      free_identity_list(il);
    1.83 -
    1.84      return NULL;
    1.85  }
    1.86  
    1.87 @@ -994,15 +984,12 @@
    1.88      if (sl == NULL)
    1.89          return NULL;
    1.90  
    1.91 -    clistiter *cur;
    1.92      stringlist_t *_sl = sl;
    1.93 -    for (cur = clist_begin(list); cur != NULL; cur = clist_next(cur)) {
    1.94 +    for (clistiter *cur = clist_begin(list); cur != NULL; cur = clist_next(cur)) {
    1.95          char *phrase = clist_content(cur);
    1.96 -        size_t index;
    1.97 -        int r;
    1.98 -
    1.99 -        index = 0;
   1.100 -        r = mailmime_encoded_phrase_parse("utf-8", phrase, strlen(phrase),
   1.101 +        size_t index = 0;
   1.102 +        
   1.103 +        const int r = mailmime_encoded_phrase_parse("utf-8", phrase, strlen(phrase),
   1.104                  &index, "utf-8", &text);
   1.105          if (r)
   1.106              goto enomem;