Changeset 1051

Show
Ignore:
Timestamp:
07/08/08 05:15:11 (2 months ago)
Author:
gyoung
Message:

Fixed 2 traps in dirsize; tcket 243

Location:
trunk/dll
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/dll/dirsize.c

    r1048 r1051  
    3333  29 Feb 08 GKY Use xfree where appropriate 
    3434  29 Feb 08 GKY Add presparams & update appearence of "Sizes" dialog 
     35  07 Jul 08 GKY Fixed trap in PMCTLS (strlen) inadequate memory allocation 
     36  07 Jul o8 GKY Fixed trap by no longer allocating pci->pszLongName as flag but pointing isroot 
     37                version to NullStr and all others to NULL. 
    3538 
    3639***********************************************************************/ 
     
    204207  // fixme to understand this - appears to be indirectly saving length, but why? 
    205208  pci->pszDisplayName = pci->pszFileName + strlen(pci->pszFileName); 
    206   pci->pszLongName = pci->pszFileName;  // fixme to be sure? 
    207209  pci->rc.pszIcon = pci->pszFileName; 
    208210  pci->rc.flRecordAttr |= CRA_RECORDREADONLY; 
     
    211213  else if (fForceLower) 
    212214    strlwr(pci->pszFileName); 
    213   pci->pszDisplayName = pci->pszFileName + strlen(pci->pszFileName); 
    214215  memset(&ri, 0, sizeof(RECORDINSERT)); 
    215216  ri.cb = sizeof(RECORDINSERT); 
     
    308309    CHAR szAllDir[80]; 
    309310    CHAR szBar[80]; 
     311    CHAR szBuf[CCHMAXPATH * 2]; 
     312 
     313# ifdef FORTIFY 
     314  Fortify_EnterScope(); 
     315# endif 
    310316 
    311317    // cbFile = currect directory usage in bytes 
     
    313319    CommaFmtULL(szCurDir, sizeof(szCurDir), pci->cbFile, 'K'); 
    314320    *szBar = 0; 
    315  
     321    pci->pszLongName = NULL; 
    316322    if (ullTotalBytes) { 
    317323      register UINT cBar; 
     
    319325      if (isroot) { 
    320326        FSALLOCATE fsa; 
    321         APIRET rc; 
    322  
    323         memset(&fsa, 0, sizeof(fsa)); 
     327        APIRET rc; 
     328 
     329 
     330        memset(&fsa, 0, sizeof(fsa)); 
    324331        rc = DosQueryFSInfo(toupper(*pci->pszFileName) - '@', FSIL_ALLOC, &fsa, 
    325332                            sizeof(FSALLOCATE)); 
     
    328335            ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector)); 
    329336        } 
    330         // Need unique buffer 23 Jul 07 SHL 
    331         pci->pszLongName = xmalloc(3, pszSrcFile, __LINE__); 
    332         if (pci->pszLongName) { 
    333           pci->pszLongName[0] = 0;      // Make null string 
    334           pci->pszLongName[1] = 1;      // Flag root - hack cough 
    335           pci->pszLongName[2] = 0;        // terminate anyway 
    336         } 
     337        // Need unique buffer 23 Jul 07 SHL 
     338        pci->pszLongName = NullStr; 
    337339      } 
    338340      else 
     
    355357    CommaFmtULL(szAllDir, sizeof(szAllDir), pci->cbFile + pci->easize, 'K'); 
    356358    c = pci->pszDisplayName - pci->pszFileName; 
    357     pci->pszFileName = xrealloc(pci->pszFileName, 
    358                                 CCHMAXPATH, 
    359                                 pszSrcFile, 
    360                                 __LINE__);      // 23 Jul 07 SHL 
    361     sprintf(pci->pszFileName + c, 
    362             "  %s + %s = %s (%.02lf%%%s)\r%s", 
     359    sprintf(szBuf, 
     360            "%s  %s + %s = %s (%.02lf%%%s)\r%s", 
     361            pci->pszFileName, 
    363362            szCurDir, 
    364363            szSubDir, 
     
    366365            fltPct, 
    367366            isroot ? GetPString(IDS_OFDRIVETEXT) : NullStr, 
    368             szBar); 
    369     pci->pszFileName = xrealloc(pci->pszFileName, 
    370                                 strlen(pci->pszFileName) + 1, 
    371                                 pszSrcFile, 
    372                                 __LINE__);      // 23 Jul 07 SHL 
     367            szBar); 
     368    free(pci->pszFileName); 
     369    pci->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__); 
    373370    pci->pszDisplayName = pci->pszFileName + c; 
    374371    WinSendMsg(hwndCnr, 
     
    673670            if (p) { 
    674671              // draw text 
    675               if (*(pci->pszLongName + 1) == 1)  // is root record 
     672              if (pci->pszLongName == NullStr)  // is root record 
    676673                GpiSetColor(oi->hps, CLR_DARKRED); 
    677674              else if (!pci->cbFile)            // no size 
     
    759756              // fill box with graph bar, flags is integer % 
    760757              if (pci->flags) { 
    761                 if (*(pci->pszLongName + 1) == 1)       // is root record 
     758                if (pci->pszLongName == NullStr)        // is root record 
    762759                  GpiSetColor(oi->hps, CLR_DARKGREEN); 
    763760                else 
     
    771768 
    772769                // draw highlights and shadows on graph 
    773                 if (*(pci->pszLongName + 1) == 1) 
     770                if (pci->pszLongName == NullStr) 
    774771                  GpiSetColor(oi->hps, CLR_GREEN); 
    775772                else 
     
    788785                ptl.x = oi->rclItem.xLeft + pci->flags * 2; 
    789786                GpiLine(oi->hps, &ptl); 
    790                 if (*(pci->pszLongName + 1) != 1) { 
     787                if (pci->pszLongName == NULL) { 
    791788                  GpiSetColor(oi->hps, CLR_DARKRED); 
    792789                  ptl.x = oi->rclItem.xLeft + 2; 
     
    839836              } // for x 
    840837              return MRFROMLONG(TRUE); 
    841             } 
     838            } 
    842839          } 
    843840        } 
  • trunk/dll/filldir.c

    r1039 r1051  
    16101610    free(psz); 
    16111611  } 
     1612# ifdef FORTIFY 
     1613  Fortify_LeaveScope(); 
     1614# endif 
    16121615} 
    16131616