Changeset 1105

Show
Ignore:
Timestamp:
08/03/08 21:34:47 (5 weeks ago)
Author:
gyoung
Message:

Reworked FillInRecSizes? cleaned up string formatting and now use pszDisplayName for the display names; It appears to have finally fixed the strlen trap.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/dll/dirsize.c

    r1104 r1105  
    3737                version to NullStr and all others to NULL. 
    3838  19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory; use pTmpDir for temp files 
     39  03 Aug 08 GKY Reworked FillInRecSizes to use pci->pszDisplayName for display names and 
     40                created a more consitent string for passing to DRAWITEM. Finally (I hope) fixed 
     41                the strlen trap. 
    3942 
    4043***********************************************************************/ 
     
    176179    pci->rc.hptrIcon = hptrDir; 
    177180    pci->attrFile = 0; 
    178     pci->pszDispAttr = NullStr; 
    179     pci->pszSubject = NullStr; 
     181    pci->pszDispAttr = NULL; 
     182    pci->pszSubject = NULL; 
    180183  } // if got something 
    181184  else { 
     
    206209    pci->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__); 
    207210  } 
    208   // fixme to understand this - appears to be indirectly saving length, but why? 
    209   pci->pszDisplayName = pci->pszFileName + strlen(pci->pszFileName); 
     211  // Use pszDisplayname for display so no need to save length of pszFileName 03 Aug 08 GKY 
     212  pci->pszDisplayName = pci->pszFileName; 
    210213  pci->rc.pszIcon = pci->pszFileName; 
    211214  pci->rc.flRecordAttr |= CRA_RECORDREADONLY; 
     
    305308 
    306309    float fltPct = 0.0; 
    307     USHORT c; 
    308310    CHAR szCurDir[80]; 
    309311    CHAR szSubDir[80]; 
    310312    CHAR szAllDir[80]; 
    311     CHAR szBar[80]; 
    312     CHAR szBuf[CCHMAXPATH + 320]; 
     313    CHAR szBar[101]; 
     314    CHAR szBuf[CCHMAXPATH + 341]; 
    313315 
    314316    // cbFile = currect directory usage in bytes 
    315317    // easize = subdirectory usage in bytes 
    316318    CommaFmtULL(szCurDir, sizeof(szCurDir), pci->cbFile, 'K'); 
    317     *szBar = 0; 
     319    *szBar = NULL; 
    318320    pci->pszLongName = NULL; 
     321    memset(szBuf, 0, sizeof(szBuf)); 
    319322    if (ullTotalBytes) { 
    320       register UINT cBar; 
     323      UINT cBar; 
    321324 
    322325      if (isroot) { 
     
    338341        fltPct = (((float)pci->cbFile + pci->easize) * 100.0) / ullTotalBytes; 
    339342 
     343      //Second line for graph reworked 03 AUG 08 GKY 
     344      memset(szBar, ' ', sizeof(szBar)); 
    340345      cBar = (UINT) fltPct / 2; 
    341       if (cBar) 
    342         memset(szBar, '#', cBar); 
    343       if (cBar * 2 != (UINT) fltPct) { 
    344         szBar[cBar] = '='; 
    345         cBar++; 
    346       } 
    347       if (cBar < 50) 
    348         memset(szBar + cBar, ' ', 50 - cBar); 
    349       szBar[50] = 0; 
     346      if (cBar && cBar * 2 != (UINT) fltPct) 
     347        szBar[cBar] = '='; 
     348      szBar[100] = 0; 
    350349    } 
    351350 
     
    353352    CommaFmtULL(szSubDir, sizeof(szSubDir), pci->easize, 'K'); 
    354353    CommaFmtULL(szAllDir, sizeof(szAllDir), pci->cbFile + pci->easize, 'K'); 
    355     c = pci->pszDisplayName - pci->pszFileName; 
    356354    sprintf(szBuf, 
    357355            "%s  %s + %s = %s (%.02lf%%%s)\r%s", 
     
    363361            isroot ? GetPString(IDS_OFDRIVETEXT) : NullStr, 
    364362            szBar); 
    365     free(pci->pszFileName); 
    366     pci->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__); 
    367     pci->pszDisplayName = pci->pszFileName + c; 
    368     WinSendMsg(hwndCnr, 
    369                CM_INVALIDATERECORD, MPFROMP(&pci), MPFROM2SHORT(1, 0)); 
     363    pci->pszDisplayName = xstrdup(szBuf, pszSrcFile, __LINE__); 
     364    // use DisplayName for display hopefully fixes "strlen" trap 02 AUG 08 GKY 
     365    if (pci->pszDisplayName) 
     366      WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pci), MPFROM2SHORT(1, 0)); 
    370367    isroot = FALSE; 
    371368  } 
     
    396393  } 
    397394  if (pciParent) { 
    398     p = strchr(pciParent->pszFileName, '\r'); 
     395    p = strchr(pciParent->pszDisplayName, '\r'); // GKY use display name for display 
    399396    if (p) 
    400397      *p = 0; 
    401398    fprintf(fp, "%*.*s%s %lu %s%s\n", 
    402399            indent * 2, indent * 2, " ", 
    403             pciParent->pszFileName, 
     400            pciParent->pszDisplayName,  // 
    404401            pciParent->attrFile, 
    405402            GetPString(IDS_FILETEXT), &"s"[pciParent->attrFile == 1]); 
     
    434431# ifdef FORTIFY 
    435432  Fortify_EnterScope(); 
     433  Fortify_BecomeOwner(dirsize);         // We free dirsize 
    436434#  endif 
    437435 
     
    664662            LONG yBottom; 
    665663            INT boxHeight; 
    666             p = strchr(pci->pszFileName, '\r'); 
     664            p = strchr(pci->pszDisplayName, '\r'); 
    667665            if (p) { 
    668666              // draw text 
     
    681679 
    682680              // Calculate nominal graph box height based on font size 
    683               GpiQueryTextBox(oi->hps, p - pci->pszFileName, 
    684                               pci->pszFileName, TXTBOX_COUNT, aptl); 
     681              GpiQueryTextBox(oi->hps, p - pci->pszDisplayName, 
     682                              pci->pszDisplayName, TXTBOX_COUNT, aptl); 
    685683              boxHeight = aptl[TXTBOX_TOPRIGHT].y - aptl[TXTBOX_BOTTOMRIGHT].y; 
    686684              boxHeight -= 4; 
     
    694692              ptl.y = yBottom + boxHeight + 6;  // 03 Aug 07 SHL 
    695693              // GpiMove(oi->hps, &ptl); 
    696               GpiCharStringAt(oi->hps, &ptl, p - pci->pszFileName, 
    697                               pci->pszFileName); 
     694              GpiCharStringAt(oi->hps, &ptl, p - pci->pszDisplayName, 
     695                              pci->pszDisplayName); 
    698696 
    699697              *p = '\r';                // Restore 
     
    852850          while (pci && (INT) pci != -1) { 
    853851            memset(szTemp, 0, sizeof(szTemp)); 
    854             strncpy(szTemp, pci->pszFileName, 
    855                     pci->pszDisplayName - pci->pszFileName); 
     852            strcpy(szTemp, pci->pszFileName); 
    856853            strrev(szTemp); 
    857854            if (*szFileName && *szTemp != '\\')