Changeset 5092:83440e7b2e52

Show
Ignore:
Timestamp:
2007-04-07 14:33:27 (20 months ago)
Author:
Michael Elkins <me@…>
Branch:
HEAD
Message:

bug #2871

Avoid altering the argument to mutt_complete() when completion fails. Previously, the trailing component of filename was removed each time the user pressed TAB.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • complete.c

    r4343 r5092  
    8080    { 
    8181      char buf[_POSIX_PATH_MAX]; 
    82       *p++ = 0; 
    83       mutt_concat_path (buf, exp_dirpart, s + 1, sizeof (buf)); 
     82      if (mutt_concatn_path (buf, sizeof(buf), exp_dirpart, strlen(exp_dirpart), s + 1, (size_t)(p - s - 1)) == NULL) { 
     83              return -1; 
     84      } 
    8485      strfcpy (exp_dirpart, buf, sizeof (exp_dirpart)); 
    85       snprintf (buf, sizeof (buf), "%s%s/", dirpart, s+1); 
    86       strfcpy (dirpart, buf, sizeof (dirpart)); 
    87       strfcpy (filepart, p, sizeof (filepart)); 
     86      mutt_substrcpy(dirpart, s, p+1, sizeof(dirpart)); 
     87      strfcpy (filepart, p + 1, sizeof (filepart)); 
    8888    } 
    8989    else 
     
    105105      else 
    106106      { 
    107         *p = 0; 
    108         len = (size_t)(p - s); 
    109         strncpy (dirpart, s, len); 
    110         dirpart[len]=0; 
    111         p++; 
    112         strfcpy (filepart, p, sizeof (filepart)); 
     107        mutt_substrcpy(dirpart, s, p, sizeof(dirpart)); 
     108        strfcpy (filepart, p + 1, sizeof (filepart)); 
    113109        strfcpy (exp_dirpart, dirpart, sizeof (exp_dirpart)); 
    114110        mutt_expand_path (exp_dirpart, sizeof (exp_dirpart)); 
  • lib.c

    r5080 r5092  
    859859} 
    860860 
     861/* 
     862 * Write the concatened pathname (dir + "/" + fname) into dst. 
     863 * The slash is ommitted when dir or fname is of 0 length. 
     864 * Returns NULL on error or a pointer to dst otherwise. 
     865 */ 
     866char *mutt_concatn_path (char *dst, size_t dstlen, 
     867    const char *dir, size_t dirlen, const char *fname, size_t fnamelen) 
     868{ 
     869  if (dstlen == 0) 
     870    return NULL; /* probably should not mask errors like this */ 
     871 
     872  /* size check */ 
     873  size_t req = dirlen + fnamelen + 1; /* +1 for the trailing nul */ 
     874  if (dirlen && fnamelen) 
     875    req++; /* when both components are non-nul, we add a "/" in between */ 
     876  if (req > dstlen) { /* check for condition where the dst length is too short */ 
     877    /* Two options here: 
     878     * 1) assert(0) or return NULL to signal error 
     879     * 2) copy as much of the path as will fit 
     880     * It doesn't appear that the return value is actually checked anywhere mutt_concat_path() 
     881     * is called, so we should just copy set dst to nul and let the calling function fail later. 
     882     */ 
     883    dst[0] = 0; /* safe since we bail out early if dstlen == 0 */ 
     884    return NULL; 
     885  } 
     886 
     887  size_t offset = 0; 
     888  if (dirlen) { /* when dir is not empty */ 
     889    memcpy(dst, dir, dirlen); 
     890    offset = dirlen; 
     891    if (fnamelen) 
     892      dst[offset++] = '/'; 
     893  } 
     894  if (fnamelen) { /* when fname is not empty */ 
     895    memcpy(dst + offset, fname, fnamelen); 
     896    offset += fnamelen; 
     897  } 
     898  dst[offset] = 0; 
     899  return dst; 
     900} 
     901 
    861902char *mutt_concat_path (char *d, const char *dir, const char *fname, size_t l) 
    862903{ 
  • lib.h

    r4896 r5092  
    137137FILE *safe_fopen (const char *, const char *); 
    138138 
     139char *mutt_concatn_path (char *, size_t, const char *, size_t, const char *, size_t); 
    139140char *mutt_concat_path (char *, const char *, const char *, size_t); 
    140141char *mutt_read_line (char *, size_t *, FILE *, int *);