Changeset 1829 for trunk/dll/misc.c


Ignore:
Timestamp:
Jul 13, 2015, 12:01:22 AM (10 years ago)
Author:
Gregg Young
Message:

Fix CN_REALLOCPSZ file name editing code to: 1) Actually reallocate the buffer. 2) Point pci->pszDisplayName into the new buffer 3) Eliminate the possibility of updating the container before CN_ENDEDIT is called. 4) Only call RemoveCnrItems for tree container and collector. Ticket [557]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/misc.c

    r1795 r1829  
    7272  12 Nov 11 GKY Fixed HelpViewer's failure to open help files and subsequent failure with files with spaces.
    7373  28 Jun 14 GKY Fix errors identified with CPPCheck
     74  12 Jul 15 GKY Fix CN_REALLOCPSZ file name editing code to: 1) Actually reallocate the buffer.
     75                2) Point pci->pszDisplayName into the new buffer 3) Eliminate the possibility
     76                of updating the container before CN_ENDEDIT is called. 4) Only call RemoveCnrItems
     77                for tree container and collector.
    7478
    7579***********************************************************************/
     
    118122#include "fortify.h"
    119123#include "info.h"                       // driveflags
     124#if 0
     125#define  __PMPRINTF__
     126#include "PMPRINTF.H"
     127#endif
    120128
    121129#define CONTAINER_COLUMNS       13      // Number of columns in details view
     
    821829MRESULT CnrDirectEdit(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    822830{
     831  static CHAR oldname[CCHMAXPATH];
     832  static CHAR newname[CCHMAXPATH];
     833  static BOOL fPostName = FALSE;
     834
    823835  switch (SHORT2FROMMP(mp1)) {
    824836  case CN_BEGINEDIT:
     
    848860      PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
    849861      PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
    850       CHAR szData[CCHMAXPATH], testname[CCHMAXPATH];
     862      CHAR testname[CCHMAXPATH];
    851863      HWND hwndMLE = WinWindowFromID(hwnd, CID_MLE);
    852864      BOOL fResetVerify = FALSE;
     865      PSZ psz;
     866      LONG retlen;
     867      APIRET rc;
    853868
    854869      if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
    855870        if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject)) {
    856 
    857           APIRET rc;
    858871          EAOP2 eaop;
    859872          PFEA2LIST pfealist = NULL;
     
    862875          USHORT len;
    863876          CHAR *eaval;
    864           LONG retlen;
    865           PSZ psz;
    866877
    867878          retlen = WinQueryWindowText(hwndMLE, sizeof(szSubject), szSubject);
     
    879890                pci->pszSubject = psz;
    880891              else {
    881                 free(pci->pszSubject);
     892                xfree(pci->pszSubject, pszSrcFile, __LINE__);
    882893                pci->pszSubject = NullStr;
    883894                return FALSE; // out of memory
     
    925936        }
    926937        else if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszLongName)) {
    927 
    928938          CHAR longname[CCHMAXPATHCOMP];
    929           LONG retlen;
    930           PSZ psz;
    931939
    932940          *longname = 0;
     
    947955                pci->pszLongName = psz;
    948956              else {
    949                 free(pci->pszLongName);
     957                xfree(pci->pszLongName, pszSrcFile, __LINE__);
    950958                pci->pszLongName = NullStr;
    951959                return FALSE; // out of memory
     
    961969        }
    962970        else {
    963           PSZ psz;
    964 
    965           WinQueryWindowText(hwndMLE, sizeof(szData), szData);
    966           if (strchr(szData, '?') ||
    967               strchr(szData, '*') || IsRoot(pci->pszFileName))
     971          WinQueryWindowText(hwndMLE, sizeof(testname), testname);
     972          // fixme to check for other illegal chars? GKY 11 Jul 15
     973          if (strchr(testname, '?') || strchr(testname, '*'))
    968974            return (MRESULT) FALSE;
    969975          // If the text changed, rename the file system object.
    970           chop_at_crnl(szData);
    971           bstrip(szData);
    972           if (!IsFullName(szData))
     976          chop_at_crnl(testname);
     977          bstrip(testname);
     978          if (!IsFullName(testname))
    973979            Runtime_Error(pszSrcFile, __LINE__, "bad name");
    974           else {
    975             if (DosQueryPathInfo(szData,
    976                                  FIL_QUERYFULLNAME,
    977                                  testname, sizeof(testname)))
     980          else {
     981            DIRCNRDATA *dcd;
     982            FILEFINDBUF4L ffb;
     983            HDIR hDir = HDIR_CREATE;
     984            ULONG nm = 1;
     985            CHAR *p;
     986
     987            if (DosQueryPathInfo(testname, //Why does this return 0 when the file doesn't exist?
     988                                 FIL_QUERYFULLNAME, // No new directory creation?
     989                                 newname, sizeof(newname)))
    978990                return FALSE;
    979991            if (DosQueryPathInfo(pci->pszFileName,
    980992                                 FIL_QUERYFULLNAME,
    981                                  szData,
    982                                  sizeof(szData)))
    983             {
    984               psz = xrealloc(pci->pszFileName, sizeof(szData), pszSrcFile, __LINE__);
    985               if (psz)
    986                 pci->pszFileName = psz;
    987               else {
    988                 free(pci->pszFileName);
    989                 pci->pszFileName = NullStr;
    990                 return FALSE; // out of memory
     993                                 oldname, sizeof(oldname)))
     994              strcpy(oldname, pci->pszFileName);
     995            psz = xrealloc(pci->pszFileName, sizeof(oldname), pszSrcFile, __LINE__);
     996            if (psz)
     997              pci->pszFileName = psz;
     998            else {
     999              xfree(pci->pszFileName, pszSrcFile, __LINE__);
     1000              pci->pszFileName = NullStr;
     1001              return FALSE; // out of memory
     1002            }
     1003            if (!dcd)    // Point pci->pszDisplayName into the realloc pci->pszFileName
     1004              dcd = INSTDATA(hwnd);
     1005            rc = xDosFindFirst(pci->pszFileName,
     1006                               &hDir,
     1007                               FILE_NORMAL | FILE_DIRECTORY |
     1008                               FILE_ARCHIVED | FILE_READONLY |
     1009                               FILE_HIDDEN | FILE_SYSTEM,
     1010                               &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL);
     1011            if (!rc) {  // file exists
     1012              DosFindClose(hDir);
     1013              if (dcd->type == DIR_FRAME || dcd->type == TREE_FRAME) {
     1014                p = strrchr(pci->pszFileName, '\\');
     1015                if (!p) {
     1016                  p = strrchr(pci->pszFileName, ':');
     1017                  if (!p)
     1018                    p = pci->pszFileName;
     1019                  else
     1020                    p++;
     1021                }
     1022                else if ((dcd && dcd->type == TREE_FRAME) ||
     1023                         !(ffb.attrFile & FILE_DIRECTORY) || !*(p + 1))
     1024                  p++;
     1025                if (!*p)
     1026                  p = pci->pszFileName;
    9911027              }
    992               strcpy(szData, pci->pszFileName);
     1028              else
     1029                p = pci->pszFileName;
     1030              pci->pszDisplayName = p;
    9931031            }
    994             WinSetWindowText(hwndMLE, szData);
    995             if (strcmp(szData, testname)) {
    996               if (stricmp(szData, testname) && IsFile(testname) != -1) {
     1032            else
     1033              return FALSE; // nothing to rename
     1034            WinSetWindowText(hwndMLE, oldname);
     1035            if (strcmp(oldname, newname)) {
     1036              if (stricmp(oldname, newname) && IsFile(newname) != -1) {
    9971037                if (!fAlertBeepOff)
    9981038                  DosBeep(50, 100);       
    9991039                return (MRESULT) FALSE;    // exists; disallow
    10001040              }
    1001               if (fVerify && (driveflags[toupper(*szData) - 'A'] & DRIVE_WRITEVERIFYOFF ||
    1002                               driveflags[toupper(*testname) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
     1041              if (fVerify && (driveflags[toupper(*oldname) - 'A'] & DRIVE_WRITEVERIFYOFF ||
     1042                              driveflags[toupper(*newname) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
    10031043                DosSetVerify(FALSE);
    10041044                fResetVerify = TRUE;
    10051045              }
    1006               if (docopyf(MOVE, szData, testname))
     1046              if (docopyf(MOVE, oldname, newname))
    10071047                Runtime_Error(pszSrcFile, __LINE__, "docopyf");
    1008               else {
    1009                 CHAR *filename;
    1010 
    1011                 filename = xstrdup(testname, pszSrcFile, __LINE__);
    1012                 if (filename) {
    1013                   if (!PostMsg(hwnd,
    1014                                UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
    1015                     free(filename);
    1016                 }
    1017                 if (stricmp(testname, pci->pszFileName)) {
    1018                   PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci));
    1019                   filename = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
    1020                   if (filename) {
    1021                     if (!PostMsg(hwnd,
    1022                                  UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
    1023                       free(filename);
    1024                   }
    1025                 }
     1048              else {
     1049                fPostName = TRUE;
    10261050              }
    10271051              if (fResetVerify) {
     
    10411065      PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord;
    10421066
     1067      if (fPostName) {
     1068        CHAR *filename;
     1069        DIRCNRDATA *dcd;
     1070
     1071        if (!dcd)
     1072          dcd = INSTDATA(hwnd);
     1073        filename = xstrdup(oldname, pszSrcFile, __LINE__);
     1074        if (filename) {
     1075          if (!PostMsg(hwnd,UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
     1076            free(filename);
     1077        }
     1078        if (dcd && (dcd->type == TREE_FRAME || dcd->type == COLLECTOR_FRAME))
     1079          PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci));
     1080        filename = xstrdup(newname, pszSrcFile, __LINE__);
     1081        if (filename) {
     1082          if (!PostMsg(hwnd, UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
     1083            free(filename);
     1084        }
     1085        fPostName = FALSE;
     1086      }
    10431087      if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
    10441088        WinSendMsg(hwnd,
Note: See TracChangeset for help on using the changeset viewer.