Changeset 1431:f82b38f77f48

Show
Ignore:
Timestamp:
2000-01-10 02:35:48 (9 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Add (and use) a function mutt_str_replace, which essentially
replaces the sequence:

safe_free (&s);
s = safe_strdup (t);

Files:
21 modified

Legend:

Unmodified
Added
Removed
  • attach.c

    r1423 r1431  
    6666  { 
    6767    mutt_copy_stream (fpin, fpout); 
    68     FREE(&a->filename); 
    69     a->filename = safe_strdup(tempfile); 
     68    mutt_str_replace (&a->filename, tempfile); 
    7069    a->unlink = 1; 
    7170 
  • browser.c

    r1423 r1431  
    933933          else 
    934934          { 
    935             safe_free ((void **) &Mask.pattern); 
     935            mutt_str_replace (&Mask.pattern, buf); 
    936936            regfree (Mask.rx); 
    937937            safe_free ((void **) &Mask.rx); 
    938             Mask.pattern = safe_strdup (buf); 
    939938            Mask.rx = rx; 
    940939            Mask.not = not; 
  • compose.c

    r1426 r1431  
    153153    { 
    154154      snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p)); 
    155       safe_free((void **) &PgpSignAs);      PgpSignAs = safe_strdup (input_signas); 
    156       safe_free((void **) &PgpSignMicalg);  PgpSignMicalg = safe_strdup (pgp_pkalg_to_mic (p->algorithm)); 
     155      mutt_str_replace (&PgpSignAs, input_signas); 
     156      mutt_str_replace (&PgpSignMicalg, pgp_pkalg_to_mic (p->algorithm)); 
    157157      pgp_free_key (&p); 
    158158       
     
    189189        } 
    190190        else  
    191         { 
    192           safe_free ((void **) &PgpSignMicalg); 
    193           PgpSignMicalg = safe_strdup (input_micalg); 
    194         } 
     191          mutt_str_replace (&PgpSignMicalg, input_micalg); 
    195192      } 
    196193    } 
     
    488485        if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) 
    489486        { 
    490           safe_free ((void **) &msg->env->subject); 
    491           msg->env->subject = safe_strdup (buf); 
     487          mutt_str_replace (&msg->env->subject, buf); 
    492488          move (HDR_SUBJECT, HDR_XOFFSET); 
    493489          clrtoeol (); 
     
    826822        if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) 
    827823        { 
    828           safe_free ((void **) &idx[menu->current]->content->description); 
    829           idx[menu->current]->content->description = safe_strdup (buf); 
     824          mutt_str_replace (&idx[menu->current]->content->description, buf); 
    830825          menu->redraw = REDRAW_CURRENT; 
    831826        } 
     
    965960            break; 
    966961           
    967           safe_free ((void **) &idx[menu->current]->content->filename); 
    968           idx[menu->current]->content->filename = safe_strdup (fname); 
     962          mutt_str_replace (&idx[menu->current]->content->filename, fname); 
    969963          menu->redraw = REDRAW_CURRENT; 
    970964 
     
    10371031 
    10381032          idx[menu->current]->content->type = itype; 
    1039           safe_free ((void **) &idx[menu->current]->content->subtype); 
    1040           idx[menu->current]->content->subtype = safe_strdup (p); 
     1033          mutt_str_replace (&idx[menu->current]->content->subtype, p); 
    10411034          idx[menu->current]->content->unlink = 1; 
    10421035          menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; 
  • curs_main.c

    r1426 r1431  
    919919        if (Context) 
    920920        { 
    921           FREE (&LastFolder); 
    922           LastFolder = safe_strdup (Context->path); 
    923         } 
    924  
    925         if (Context) 
    926         { 
     921          mutt_str_replace (&LastFolder, Context->path); 
     922 
    927923          if (mx_close_mailbox (Context) != 0) 
    928924          { 
  • edit.c

    r1423 r1431  
    254254    strfcpy (tmp, e->subject ? e->subject: "", sizeof (tmp)); 
    255255    if (mutt_enter_string ((unsigned char *) tmp, sizeof (tmp), LINES-1, 9, 0) == 0) 
    256     { 
    257       safe_free ((void **) &e->subject); 
    258       e->subject = safe_strdup (tmp); 
    259     } 
     256      mutt_str_replace (&e->subject, tmp); 
    260257    addch ('\n'); 
    261258  } 
     
    392389          break; 
    393390        case 's': 
    394           safe_free ((void **) &msg->env->subject); 
    395           msg->env->subject = safe_strdup (p); 
     391          mutt_str_replace (&msg->env->subject, p); 
    396392          break; 
    397393        case 't': 
  • history.c

    r1196 r1431  
    8080    if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0) 
    8181    { 
    82       safe_free ((void **) &h->hist[h->last]); 
    83       h->hist[h->last++] = safe_strdup (s); 
     82      mutt_str_replace (&h->hist[h->last++], s); 
    8483      if (h->last > HistSize - 1) 
    8584        h->last = 0; 
  • init.c

    r1423 r1431  
    654654    case DT_STR: 
    655655      if (p->init) 
    656       { 
    657         FREE (p->data); 
    658         *((char **) p->data) = safe_strdup ((char *) p->init); 
    659       } 
     656        mutt_str_replace ((char **) p->data, (char *) p->init);  
    660657      break; 
    661658    case DT_PATH: 
     
    664661        char path[_POSIX_PATH_MAX]; 
    665662 
    666         FREE (p->data); 
    667663        strfcpy (path, (char *) p->init, sizeof (path)); 
    668664        mutt_expand_path (path, sizeof (path)); 
    669         *((char **) p->data) = safe_strdup (path); 
     665        mutt_str_replace ((char **) p->data, path); 
    670666      } 
    671667      break; 
  • lib.c

    r1423 r1431  
    144144} 
    145145 
     146void mutt_str_replace (char **p, const char *s) 
     147{ 
     148  if (*p) 
     149    free (*p); 
     150  *p = safe_strdup (s); 
     151} 
     152 
    146153/* convert all characters in the string to lowercase */ 
    147154char *mutt_strlower (char *s) 
  • main.c

    r1423 r1431  
    397397 
    398398      case 'F': 
    399         FREE (&Muttrc); 
    400         Muttrc = safe_strdup (optarg); 
     399        mutt_str_replace (&Muttrc, optarg); 
    401400        break; 
    402401 
  • menu.c

    r1423 r1431  
    659659                         buf, sizeof (buf), M_CLEAR) != 0 || !buf[0]) 
    660660      return (-1); 
    661     safe_free ((void **) &menu->searchBuf); 
    662     menu->searchBuf = safe_strdup (buf); 
     661    mutt_str_replace (&menu->searchBuf, buf); 
    663662    menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP; 
    664663  } 
  • mh.c

    r1423 r1431  
    501501    { 
    502502      if (hdr)  
    503       { 
    504         FREE (&hdr->path); 
    505         hdr->path = safe_strdup (path); 
    506       } 
     503        mutt_str_replace (&hdr->path, path); 
    507504      FREE (&msg->path); 
    508505      return 0; 
     
    576573    { 
    577574      if (hdr) 
    578       { 
    579         FREE (&hdr->path); 
    580         hdr->path = safe_strdup (tmp); 
    581       } 
     575        mutt_str_replace (&hdr->path, tmp); 
    582576      FREE (&msg->path); 
    583577      return 0; 
     
    649643      snprintf (newpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path); 
    650644      if ((rc = safe_rename (newpath, oldpath)) == 0) 
    651       { 
    652         FREE (&h->path); 
    653         h->path = safe_strdup (partpath); 
    654       } 
     645        mutt_str_replace (&h->path, partpath); 
    655646    } 
    656647  } 
     
    720711      return (-1); 
    721712    } 
    722     safe_free ((void **) &h->path); 
    723     h->path = safe_strdup (partpath); 
     713    mutt_str_replace (&h->path, partpath); 
    724714  } 
    725715  return (0); 
     
    929919 
    930920      if(mutt_strcmp(ctx->hdrs[i]->path, p->h->path)) 
    931       { 
    932         safe_free((void **) &ctx->hdrs[i]->path); 
    933         ctx->hdrs[i]->path = safe_strdup(p->h->path); 
    934       } 
     921        mutt_str_replace (&ctx->hdrs[i]->path, p->h->path); 
    935922 
    936923      if(modified) 
  • muttlib.c

    r1423 r1431  
    404404    if (mutt_strcasecmp (attribute, q->attribute) == 0) 
    405405    { 
    406       safe_free((void **) &q->value); 
    407       q->value = safe_strdup(value); 
     406      mutt_str_replace (&q->value, value); 
    408407      return; 
    409408    } 
  • parse.c

    r1424 r1431  
    349349       * specified. 
    350350       */ 
    351       safe_free ((void **) &ct->filename); 
    352       ct->filename = safe_strdup (s);  
     351      mutt_str_replace (&ct->filename, s); 
    353352    } 
    354353    if ((s = mutt_get_parameter ("name", parms)) != 0) 
     
    407406      else if (!mutt_strcasecmp ("description", line + 8)) 
    408407      { 
    409         safe_free ((void **) &p->description); 
    410         p->description = safe_strdup (c); 
     408        mutt_str_replace (&p->description, c); 
    411409        rfc2047_decode (p->description, p->description, mutt_strlen (p->description) + 1); 
    412410      } 
     
    456454  { 
    457455    b->type = TYPETEXT; 
    458     safe_free ((void **) &b->subtype); 
    459     b->subtype = safe_strdup ("plain"); 
     456    mutt_str_replace (&b->subtype, "plain"); 
    460457  } 
    461458} 
     
    989986            if (hdr) 
    990987            { 
    991               safe_free ((void **) &hdr->content->description); 
    992               hdr->content->description = safe_strdup (p); 
     988              mutt_str_replace (&hdr->content->description, p); 
    993989              rfc2047_decode (hdr->content->description, 
    994990                              hdr->content->description, 
     
    10091005        if (!mutt_strcasecmp ("ate", line + 1)) 
    10101006        { 
    1011           safe_free((void **)&e->date); 
    1012           e->date = safe_strdup(p); 
     1007          mutt_str_replace (&e->date, p); 
    10131008          if (hdr) 
    10141009            hdr->date_sent = mutt_parse_date (p, hdr); 
  • pgpkey.c

    r1405 r1431  
    619619    { 
    620620      if (l) 
    621       { 
    622         safe_free ((void **) &l->dflt); 
    623         l->dflt = safe_strdup (resp); 
    624       } 
     621        mutt_str_replace (&l->dflt, resp); 
    625622      else 
    626623      { 
  • postpone.c

    r1423 r1431  
    483483  
    484484  if (set_signas || *pgp_sign_as) 
    485   { 
    486     safe_free((void **) &PgpSignAs); 
    487     PgpSignAs = safe_strdup(pgp_sign_as); 
    488   } 
     485    mutt_str_replace (&PgpSignAs, pgp_sign_as); 
    489486 
    490487  /* the micalg field must not be empty */ 
    491488  if (set_signas && *pgp_sign_micalg) 
    492   { 
    493     safe_free((void **) &PgpSignMicalg); 
    494     PgpSignMicalg = safe_strdup(pgp_sign_micalg); 
    495   } 
     489    mutt_str_replace (&PgpSignMicalg, pgp_sign_micalg); 
    496490 
    497491  return pgp; 
     
    625619    } 
    626620     
    627     safe_free ((void *) &b->filename); 
    628     b->filename = safe_strdup (file); 
     621    mutt_str_replace (&b->filename, file); 
    629622    b->unlink = 1; 
    630623 
  • protos.h

    r1426 r1431  
    195195void mutt_signal_init (void); 
    196196void mutt_stamp_attachment (BODY *a); 
     197void mutt_str_replace (char **p, const char *s); 
    197198void mutt_tabs_to_spaces (char *); 
    198199void mutt_tag_set_flag (int, int); 
  • recvattach.c

    r1426 r1431  
    8989    { 
    9090      if (mutt_strcmp (idx[x]->tree, buf) != 0) 
    91       { 
    92         safe_free ((void **) &idx[x]->tree); 
    93         idx[x]->tree = safe_strdup (buf); 
    94       } 
     91        mutt_str_replace (&idx[x]->tree, buf); 
    9592    } 
    9693    else 
  • rfc1524.c

    r1423 r1431  
    151151      field++; 
    152152      field = mutt_skip_whitespace (field); 
    153       safe_free ((void **) entry); 
    154       *entry = safe_strdup (field); 
     153      mutt_str_replace (entry, field); 
    155154    } 
    156155    return 1; 
  • rfc2047.c

    r1423 r1431  
    260260    { 
    261261      rfc2047_encode_string (buffer, sizeof (buffer), (const unsigned char *)ptr->personal); 
    262       safe_free ((void **) &ptr->personal); 
    263       ptr->personal = safe_strdup (buffer); 
     262      mutt_str_replace (&ptr->personal, buffer); 
    264263    } 
    265264#ifdef EXACT_ADDRESS 
     
    267266    { 
    268267      rfc2047_encode_string (buffer, sizeof (buffer), (const unsigned char *)ptr->val); 
    269       safe_free ((void **) &ptr->val); 
    270       ptr->val = safe_strdup (buffer); 
     268      mutt_str_replace (&ptr->val, buffer); 
    271269    } 
    272270#endif 
  • send.c

    r1423 r1431  
    235235    return (-1); 
    236236  } 
    237   safe_free ((void **) &en->subject); 
    238   en->subject = safe_strdup (buf); 
     237  mutt_str_replace (&en->subject, buf); 
    239238 
    240239  return 0; 
     
    915914    { 
    916915      rfc2047_encode_string (tmp, sizeof (tmp), (unsigned char *) t->description); 
    917       safe_free ((void **) &t->description); 
    918       t->description = safe_strdup (tmp); 
     916      mutt_str_replace (&t->description, tmp); 
    919917    } 
    920918    if (t->parts) 
  • sendlib.c

    r1423 r1431  
    13821382      len = mutt_strlen (tmp); 
    13831383      rfc2047_encode_string (tmp + len, sizeof (tmp) - len, (unsigned char *) p); 
    1384       safe_free ((void **) &h->data); 
    1385       h->data = safe_strdup (tmp); 
     1384      mutt_str_replace (&h->data, tmp); 
    13861385    } 
    13871386  } 
     
    18121811    rfc2047_encode_string (buffer, sizeof (buffer) - 1, 
    18131812                           (unsigned char *) env->subject); 
    1814     safe_free ((void **) &env->subject); 
    1815     env->subject = safe_strdup (buffer); 
     1813    mutt_str_replace (&env->subject, buffer); 
    18161814  } 
    18171815  encode_headers (env->userhdrs);