Changeset 1892 for trunk/dll/filldir.c


Ignore:
Timestamp:
Jan 31, 2020, 6:45:23 AM (6 years ago)
Author:
Steven Levine
Message:

Rework RemoveCnrItems to avoid possible traps on bad input.
Rework RemoveArcItems like RemoveCnrItems.
Sync source with standards.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/filldir.c

    r1891 r1892  
    125125  26 Sep 15 GKY Remove fInitialDriveScan code
    126126  28 Jan 20 SHL EmptyCnr: report more errors
    127   29 Jan 20 SHL RemoveCnrItems: rework removal from prev/next chain
     127  29 Jan 20 SHL Rework RemoveCnrItems removal to not use prev/next chain
     128  30 Jan 20 SHL Rework RemoveCnrItems to avoid possible traps on bad input
     129  30 Jan 20 SHL Clean up some inconsistent formatting
    128130
    129131***********************************************************************/
     
    297299      hptr = hptrArt;
    298300    else
    299       hptr = (HPOINTER) 0;
     301      hptr = (HPOINTER)0;
    300302  }
    301303  else
    302     hptr = (HPOINTER) 0;
     304    hptr = (HPOINTER)0;
    303305
    304306  return hptr;
     
    319321
    320322  // try to guess WPS default file icon
    321   hptr2 = (HPOINTER) 0;
     323  hptr2 = (HPOINTER)0;
    322324  for (u = 0; !hptrWPSFile && u < 10; u++) {
    323325    char szFileName[CCHMAXPATH];
     
    367369  ULONG flags = driveflags[toupper(*pci->pszFileName) - 'A'];
    368370  BOOL fLoadSubjectForDrive = fLoadSubject && ~flags & DRIVE_NOLOADSUBJS;
    369   BOOL fLoadLongNameForDrive = fLoadLongnames &&        // ~flags & DRIVE_NOLONGNAMES &&
     371  BOOL fLoadLongNameForDrive = fLoadLongnames &&        // ~flags & DRIVE_NOLONGNAMES &&
    370372                               ~flags & DRIVE_NOLOADLONGS;
    371373  if (fLoadSubjectForDrive || fLoadLongNameForDrive) {
     
    411413        eaop.fpFEA2List = pfealist;
    412414        eaop.oError = 0;
    413         rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
    414                               (PVOID) &eaop, (ULONG) sizeof(EAOP2));
     415        rc = DosQueryPathInfo(pci->pszFileName,
     416                              FIL_QUERYEASFROMLIST,
     417                              (PVOID)&eaop,
     418                              (ULONG)sizeof(EAOP2));
    415419        // Prevent this error from occuring when scanning a directory
    416420        // that contains a locked data file
     
    533537        (flags & DRIVE_NOLOADICONS) ||
    534538        !isalpha(*pci->pszFileName)) {
    535       hptr = (HPOINTER) 0;
     539      hptr = (HPOINTER)0;
    536540    }
    537541    else
     
    543547        (flags & DRIVE_NOLOADICONS) ||
    544548        !isalpha(*pci->pszFileName)) {
    545       hptr = (HPOINTER) 0;
     549      hptr = (HPOINTER)0;
    546550    }
    547551    else
     
    630634               != (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)))) {
    631635    if (*dcd->mask.szMask || dcd->mask.antiattr) {
    632       if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
     636      if (!Filter((PMINIRECORDCORE)pci, (PVOID)&dcd->mask))
    633637        pci->rc.flRecordAttr |= CRA_FILTERED;
    634638    }
     
    792796        (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)))) {
    793797    if (*dcd->mask.szMask || dcd->mask.antiattr) {
    794       if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
     798      if (!Filter((PMINIRECORDCORE)pci, (PVOID)&dcd->mask))
    795799        pci->rc.flRecordAttr |= CRA_FILTERED;
    796800    }
     
    954958                                               pffbFile, partial, dcd);
    955959                pciNext = pci;
    956                 pci = (PCNRITEM) pci->rc.preccNextRecord;
     960                pci = (PCNRITEM)pci->rc.preccNextRecord;
    957961                ullTotalBytes += ullBytes;
    958962              } // for
     
    960964              memset(&ri, 0, sizeof(RECORDINSERT));
    961965              ri.cb = sizeof(RECORDINSERT);
    962               ri.pRecordOrder = (PRECORDCORE) CMA_END;
    963               ri.pRecordParent = (PRECORDCORE) pciParent;
    964               ri.zOrder = (ULONG) CMA_TOP;
     966              ri.pRecordOrder = (PRECORDCORE)CMA_END;
     967              ri.pRecordParent = (PRECORDCORE)pciParent;
     968              ri.zOrder = (ULONG)CMA_TOP;
    965969              ri.cRecordsInsert = ulSelCnt;
    966970              ri.fInvalidateRecord = TRUE;
     
    978982                  ok = FALSE;
    979983                  ullTotalBytes = 0;
    980                   if (WinIsWindow((HAB) 0, hwndCnr))
     984                  if (WinIsWindow((HAB)0, hwndCnr))
    981985                    FreeCnrItemList(hwndCnr, pciFirst);
    982986                }
     
    10931097              ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
    10941098                                          pffbFile, partial, dcd);
    1095               pci = (PCNRITEM) pci->rc.preccNextRecord;
     1099              pci = (PCNRITEM)pci->rc.preccNextRecord;
    10961100              ullTotalBytes += ullBytes;
    10971101              DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     
    11131117            memset(&ri, 0, sizeof(RECORDINSERT));
    11141118            ri.cb = sizeof(RECORDINSERT);
    1115             ri.pRecordOrder = (PRECORDCORE) CMA_END;
    1116             ri.pRecordParent = (PRECORDCORE) pciParent;
    1117             ri.zOrder = (ULONG) CMA_TOP;
     1119            ri.pRecordOrder = (PRECORDCORE)CMA_END;
     1120            ri.pRecordParent = (PRECORDCORE)pciParent;
     1121            ri.zOrder = (ULONG)CMA_TOP;
    11181122            ri.cRecordsInsert = ulRecsToInsert;
    11191123            ri.fInvalidateRecord = (!fSyncUpdates && dcd &&
     
    11301134                ok = FALSE;
    11311135                ullTotalBytes = 0;
    1132                 if (WinIsWindow((HAB) 0, hwndCnr))
     1136                if (WinIsWindow((HAB)0, hwndCnr))
    11331137                  FreeCnrItemList(hwndCnr, pciFirst);
    11341138                pciFirst = NULL;
     
    12711275  if (!DosQuerySysInfo(QSV_BOOT_DRIVE,
    12721276                       QSV_BOOT_DRIVE,
    1273                        (PVOID) &startdrive,
    1274                        (ULONG) sizeof(ULONG)) &&
     1277                       (PVOID)&startdrive,
     1278                       (ULONG)sizeof(ULONG)) &&
    12751279      startdrive)
    12761280  {
     
    13061310                          CM_ALLOCRECORD,
    13071311                          MPFROMLONG(EXTRA_RECORD_BYTES),
    1308                           MPFROMLONG((ULONG) numtoinsert));
     1312                          MPFROMLONG((ULONG)numtoinsert));
    13091313  }
    13101314
     
    13511355              CHAR Key[80];
    13521356
    1353               sprintf(Key, "%c.VerifyOffChecked", (CHAR) (iDrvNum + 'A'));
     1357              sprintf(Key, "%c.VerifyOffChecked", (CHAR)(iDrvNum + 'A'));
    13541358              fVerifyOffChecked[iDrvNum] = TRUE;
    13551359              PrfWriteProfileData(fmprof, appname, Key, &fVerifyOffChecked[iDrvNum], sizeof(BOOL));
     
    13701374            rc = DosQueryPathInfo(szDrive,
    13711375                                  FIL_QUERYEASIZEL,
    1372                                   &fsa4, (ULONG) sizeof(FILESTATUS4L));
     1376                                  &fsa4,
     1377                                  (ULONG)sizeof(FILESTATUS4L));
    13731378            if (rc == ERROR_BAD_NET_RESP) {
    13741379              DosError(FERR_DISABLEHARDERR);
    13751380              rc = DosQueryPathInfo(szDrive,
    13761381                                    FIL_STANDARDL,
    1377                                     &fsa4, (ULONG) sizeof(FILESTATUS4L));
     1382                                    &fsa4,
     1383                                    (ULONG)sizeof(FILESTATUS4L));
    13781384              fsa4.cbList = 0;
    13791385            }
     
    14491455      }
    14501456      pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
    1451       pci = (PCNRITEM) pci->rc.preccNextRecord; // next rec
     1457      pci = (PCNRITEM)pci->rc.preccNextRecord;  // next rec
    14521458    }
    14531459    else if (~ulDriveMap & ulDriveMapMask)
     
    14821488    memset(&ri, 0, sizeof(RECORDINSERT));
    14831489    ri.cb = sizeof(RECORDINSERT);
    1484     ri.pRecordOrder = (PRECORDCORE) CMA_END;
    1485     ri.pRecordParent = (PRECORDCORE) NULL;
    1486     ri.zOrder = (ULONG) CMA_TOP;
     1490    ri.pRecordOrder = (PRECORDCORE)CMA_END;
     1491    ri.pRecordParent = (PRECORDCORE)NULL;
     1492    ri.zOrder = (ULONG)CMA_TOP;
    14871493    ri.cRecordsInsert = numtoinsert;
    14881494    ri.fInvalidateRecord = FALSE;
     
    14961502
    14971503  // move cursor onto the default drive rather than the first drive
    1498   pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1499                               CM_QUERYRECORD,
    1500                               MPVOID,
    1501                               MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
     1504  pci = (PCNRITEM)WinSendMsg(hwndCnr,
     1505                             CM_QUERYRECORD,
     1506                             MPVOID,
     1507                             MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
    15021508  while (pci && (INT)pci != -1) {
    1503     if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum) {
     1509    if ((ULONG)(toupper(*pci->pszFileName) - '@') == ulCurDriveNum) {
    15041510      WinSendMsg(hwndCnr,
    15051511                 CM_SETRECORDEMPHASIS,
     
    15071513      break;
    15081514    }
    1509     pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1510                                 CM_QUERYRECORD,
    1511                                 MPFROMP(pci),
    1512                                 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     1515    pci = (PCNRITEM)WinSendMsg(hwndCnr,
     1516                               CM_QUERYRECORD,
     1517                               MPFROMP(pci),
     1518                               MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    15131519  }
    15141520
     
    15281534      memset(&ri, 0, sizeof(RECORDINSERT));
    15291535      ri.cb = sizeof(RECORDINSERT);
    1530       ri.pRecordOrder = (PRECORDCORE) CMA_END;
    1531       ri.pRecordParent = (PRECORDCORE) NULL;
    1532       ri.zOrder = (ULONG) CMA_TOP;
     1536      ri.pRecordOrder = (PRECORDCORE)CMA_END;
     1537      ri.pRecordParent = (PRECORDCORE)NULL;
     1538      ri.zOrder = (ULONG)CMA_TOP;
    15331539      ri.cRecordsInsert = 1;
    15341540      ri.fInvalidateRecord = FALSE;
     
    15651571              memset(&ri, 0, sizeof(RECORDINSERT));
    15661572              ri.cb = sizeof(RECORDINSERT);
    1567               ri.pRecordOrder = (PRECORDCORE) CMA_END;
    1568               ri.pRecordParent = (PRECORDCORE) pciParent;
    1569               ri.zOrder = (ULONG) CMA_TOP;
     1573              ri.pRecordOrder = (PRECORDCORE)CMA_END;
     1574              ri.pRecordParent = (PRECORDCORE)pciParent;
     1575              ri.zOrder = (ULONG)CMA_TOP;
    15701576              ri.cRecordsInsert = 1;
    15711577              ri.fInvalidateRecord = FALSE;
     
    15911597
    15921598  // Run Stubby on each hard drive to ensure expand/collapse buttons correct
    1593   pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1594                               CM_QUERYRECORD,
    1595                               MPVOID,
    1596                               MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
     1599  pci = (PCNRITEM)WinSendMsg(hwndCnr,
     1600                             CM_QUERYRECORD,
     1601                             MPVOID,
     1602                             MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
    15971603  while (pci && (INT)pci != -1) {
    1598     pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
    1599                                     CM_QUERYRECORD,
    1600                                     MPFROMP(pci),
    1601                                     MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     1604    pciNext = (PCNRITEM)WinSendMsg(hwndCnr,
     1605                                   CM_QUERYRECORD,
     1606                                   MPFROMP(pci),
     1607                                   MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    16021608    if (~pci->flags & RECFLAGS_ENV) {
    16031609      iDrvNum = toupper(*pci->pszFileName) - 'A';       // 0..25
     
    16271633
    16281634  // Fill in environment CNRITEMs, if any
    1629   pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1630                               CM_QUERYRECORD,
    1631                               MPVOID,
    1632                               MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
     1635  pci = (PCNRITEM)WinSendMsg(hwndCnr,
     1636                             CM_QUERYRECORD,
     1637                             MPVOID,
     1638                             MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
    16331639  while (pci && (INT)pci != -1) {
    1634     pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
    1635                                     CM_QUERYRECORD,
    1636                                     MPFROMP(pci),
    1637                                     MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     1640    pciNext = (PCNRITEM)WinSendMsg(hwndCnr,
     1641                                   CM_QUERYRECORD,
     1642                                   MPFROMP(pci),
     1643                                   MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    16381644    if (pci->flags & RECFLAGS_ENV) {
    16391645      pci = (PCNRITEM) WinSendMsg(hwndCnr,
     
    16451651        if (pci->flags & RECFLAGS_ENV)
    16461652          AddFleshWorkRequest(hwndCnr, pci, eFleshEnv);
    1647         pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1648                                     CM_QUERYRECORD,
    1649                                     MPFROMP(pci),
    1650                                     MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     1653        pci = (PCNRITEM)WinSendMsg(hwndCnr,
     1654                                   CM_QUERYRECORD,
     1655                                   MPFROMP(pci),
     1656                                   MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    16511657      }
    16521658      break;
    16531659    }
    1654     pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1655                                 CM_QUERYRECORD,
    1656                                 MPFROMP(pci),
    1657                                 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     1660    pci = (PCNRITEM)WinSendMsg(hwndCnr,
     1661                               CM_QUERYRECORD,
     1662                               MPFROMP(pci),
     1663                               MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    16581664  } // while pci
    16591665
     
    17631769
    17641770  // Remove field info descriptors
    1765   pfi = (PFIELDINFO) WinSendMsg(hwnd, CM_QUERYDETAILFIELDINFO, MPVOID,
    1766                                 MPFROMSHORT(CMA_FIRST));
     1771  pfi = (PFIELDINFO)WinSendMsg(hwnd,
     1772                               CM_QUERYDETAILFIELDINFO,
     1773                               MPVOID,
     1774                               MPFROMSHORT(CMA_FIRST));
    17671775  if (pfi &&
    17681776      (INT)WinSendMsg(hwnd, CM_REMOVEDETAILFIELDINFO, MPVOID,
     
    19551963  InitITimer(&itdSleep, 500);
    19561964  for (usCount = 0; pci; usCount++) {
    1957     pciNext = (PCNRITEM) pci->rc.preccNextRecord;
     1965    pciNext = (PCNRITEM)pci->rc.preccNextRecord;
    19581966    FreeCnrItemData(pci);
    19591967    pci = pciNext;
    19601968    if (!IdleIfNeeded(&itdSleep, 30)) {
    19611969      for (usCount = usCount + 1; pci; usCount++) {
    1962         pciNext = (PCNRITEM) pci->rc.preccNextRecord;
     1970        pciNext = (PCNRITEM)pci->rc.preccNextRecord;
    19631971        FreeCnrItemData(pci);
    19641972        pci = pciNext;
     
    19781986/**
    19791987 * Remove item(s) from container and free associated storage if requested
    1980  * @param pciFirst points to first item to remove or NULL to remove all
     1988 * @param pciFirst points to specific item to remove or NULL to remove all
    19811989 * @param usCnt is 0 to remove all or 1 to remove specific record
    19821990 * @param usFlags for CM_REMOVERECORD
     
    19972005    remaining = -1;
    19982006  }
    1999   else if (!usFlags & CMA_FREE) {
     2007  if (!usFlags & CMA_FREE) {
    20002008    Runtime_Error(pszSrcFile, __LINE__, "usFlags must have CMA_FREE set");
    20012009    remaining = -1;
    20022010  }
    2003   else if (!pciFirst) {
     2011  if (!pciFirst) {
    20042012    // Removing all - query first
    20052013    pciFirst = (PCNRITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
     
    20212029  // 2020-01-28 SHL Rework to use CMA_NEXT - preccNextRecord method was never reliable
    20222030  pci = pciFirst;
    2023   while (pci && (INT)pci != -1) {
     2031  while (pci && (INT)pci != -1 && remaining > 0) {
    20242032    FreeCnrItemData(pci);
    2025     if (remaining && --remaining == 0)
    2026       break;                    // pci point to last CNRITEM to be deleted
     2033    if (--remaining == 0)
     2034      break;
    20272035    pci = WinSendMsg(hwnd, CM_QUERYRECORD, MPFROMP(pci),
    20282036                     MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     
    20432051    remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&pciFirst), MPFROM2SHORT(usCnt, usFlags));
    20442052    if (remaining == -1)
    2045       Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pci %p cnt %u", hwnd, pciFirst, usCnt);
     2053      Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pciFirst %p cnt %u", hwnd, pciFirst, usCnt);
    20462054    else if (usCnt == 0 && remaining != 0)
    20472055      Runtime_Error(pszSrcFile, __LINE__, "%u records remain after CM_REMOVERECORD", remaining);
Note: See TracChangeset for help on using the changeset viewer.