mirror of
https://github.com/reactos/reactos.git
synced 2024-06-21 13:31:38 +00:00
[CMD] Add missing memory allocation NULL checks (#161). CORE-8304
Adapted from a patch by Jacob S. Preciado. Bring also the code suggestions emitted during review.
This commit is contained in:
parent
73798d2e71
commit
3f892a8d6b
|
@ -64,7 +64,10 @@ PrintAlias (VOID)
|
||||||
/* allocate memory for an extra \0 char to make parsing easier */
|
/* allocate memory for an extra \0 char to make parsing easier */
|
||||||
ptr = cmd_alloc(len + sizeof(TCHAR));
|
ptr = cmd_alloc(len + sizeof(TCHAR));
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for ptr!\n");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Aliases = ptr;
|
Aliases = ptr;
|
||||||
|
|
||||||
|
@ -107,6 +110,7 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen)
|
||||||
buffer = cmd_alloc(maxlen);
|
buffer = cmd_alloc(maxlen);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for alias buffer!\n");
|
||||||
cmd_free(tmp);
|
cmd_free(tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,44 +33,40 @@ PrintAssociation(LPTSTR extension)
|
||||||
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return_val = RegOpenKeyEx(hKey, extension, 0, KEY_READ, &hInsideKey);
|
return_val = RegOpenKeyEx(hKey, extension, 0, KEY_READ, &hInsideKey);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
RegCloseKey(hInsideKey);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* obtain string length */
|
/* obtain string length */
|
||||||
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, NULL, &fileTypeLength);
|
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, NULL, &fileTypeLength);
|
||||||
|
|
||||||
if (return_val == ERROR_FILE_NOT_FOUND) /* no default value, don't display */
|
if (return_val == ERROR_FILE_NOT_FOUND) /* no default value, don't display */
|
||||||
{
|
{
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
RegCloseKey(hKey);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
RegCloseKey(hKey);
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileType = cmd_alloc(fileTypeLength * sizeof(TCHAR));
|
fileType = cmd_alloc(fileTypeLength * sizeof(TCHAR));
|
||||||
|
if (!fileType)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for fileType!\n");
|
||||||
|
RegCloseKey(hInsideKey);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
/* obtain actual file type */
|
/* obtain actual file type */
|
||||||
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, (LPBYTE) fileType, &fileTypeLength);
|
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, (LPBYTE)fileType, &fileTypeLength);
|
||||||
|
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
RegCloseKey(hKey);
|
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
@ -78,19 +74,17 @@ PrintAssociation(LPTSTR extension)
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileTypeLength != 0) /* if there is a default key, display relevant information */
|
if (fileTypeLength != 0) /* if there is a default key, display relevant information */
|
||||||
{
|
{
|
||||||
ConOutPrintf(_T("%s=%s\n"), extension, fileType);
|
ConOutPrintf(_T("%s=%s\n"), extension, fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileTypeLength)
|
cmd_free(fileType);
|
||||||
cmd_free(fileType);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT
|
static INT
|
||||||
PrintAllAssociations()
|
PrintAllAssociations(VOID)
|
||||||
{
|
{
|
||||||
DWORD return_val = 0;
|
DWORD return_val = 0;
|
||||||
HKEY hKey = NULL;
|
HKEY hKey = NULL;
|
||||||
|
@ -103,10 +97,7 @@ PrintAllAssociations()
|
||||||
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return_val = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numKeys, &extLength, NULL, NULL, NULL, NULL, NULL, NULL);
|
return_val = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numKeys, &extLength, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
@ -118,8 +109,14 @@ PrintAllAssociations()
|
||||||
|
|
||||||
extLength++;
|
extLength++;
|
||||||
extName = cmd_alloc(extLength * sizeof(TCHAR));
|
extName = cmd_alloc(extLength * sizeof(TCHAR));
|
||||||
|
if (!extName)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for extName!\n");
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
for(keyCtr = 0; keyCtr < numKeys; keyCtr++)
|
for (keyCtr = 0; keyCtr < numKeys; keyCtr++)
|
||||||
{
|
{
|
||||||
DWORD buffer_size = extLength;
|
DWORD buffer_size = extLength;
|
||||||
return_val = RegEnumKeyEx(hKey, keyCtr, extName, &buffer_size, NULL, NULL, NULL, NULL);
|
return_val = RegEnumKeyEx(hKey, keyCtr, extName, &buffer_size, NULL, NULL, NULL, NULL);
|
||||||
|
@ -139,9 +136,7 @@ PrintAllAssociations()
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if (extName)
|
cmd_free(extName);
|
||||||
cmd_free(extName);
|
|
||||||
|
|
||||||
return numKeys;
|
return numKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,28 +152,20 @@ AddAssociation(LPTSTR extension, LPTSTR type)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return_val = RegCreateKeyEx(hKey, extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &insideKey, NULL);
|
return_val = RegCreateKeyEx(hKey, extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &insideKey, NULL);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return_val = RegSetValueEx(insideKey, NULL, 0, REG_SZ, (LPBYTE)type, (_tcslen(type) + 1) * sizeof(TCHAR));
|
return_val = RegSetValueEx(insideKey, NULL, 0, REG_SZ, (LPBYTE)type, (_tcslen(type) + 1) * sizeof(TCHAR));
|
||||||
|
RegCloseKey(insideKey);
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
|
||||||
RegCloseKey(insideKey);
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
|
||||||
|
|
||||||
RegCloseKey(insideKey);
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
RemoveAssociation(LPTSTR extension)
|
RemoveAssociation(LPTSTR extension)
|
||||||
{
|
{
|
||||||
|
@ -191,19 +178,15 @@ RemoveAssociation(LPTSTR extension)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return_val = RegDeleteKey(hKey, extension);
|
return_val = RegDeleteKey(hKey, extension);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if (return_val != ERROR_SUCCESS)
|
if (return_val != ERROR_SUCCESS)
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return -2;
|
return -2;
|
||||||
}
|
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INT CommandAssoc (LPTSTR param)
|
INT CommandAssoc (LPTSTR param)
|
||||||
{
|
{
|
||||||
/* print help */
|
/* print help */
|
||||||
|
@ -216,7 +199,9 @@ INT CommandAssoc (LPTSTR param)
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
if (_tcslen(param) == 0)
|
if (_tcslen(param) == 0)
|
||||||
|
{
|
||||||
PrintAllAssociations();
|
PrintAllAssociations();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LPTSTR lpEqualSign = _tcschr(param, _T('='));
|
LPTSTR lpEqualSign = _tcschr(param, _T('='));
|
||||||
|
@ -224,9 +209,15 @@ INT CommandAssoc (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR fileType = lpEqualSign + 1;
|
LPTSTR fileType = lpEqualSign + 1;
|
||||||
LPTSTR extension = cmd_alloc((lpEqualSign - param + 1) * sizeof(TCHAR));
|
LPTSTR extension = cmd_alloc((lpEqualSign - param + 1) * sizeof(TCHAR));
|
||||||
|
if (!extension)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for extension!\n");
|
||||||
|
error_out_of_memory();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
_tcsncpy(extension, param, lpEqualSign - param);
|
_tcsncpy(extension, param, lpEqualSign - param);
|
||||||
extension[lpEqualSign - param] = (TCHAR)0;
|
extension[lpEqualSign - param] = _T('\0');
|
||||||
|
|
||||||
if (_tcslen(fileType) == 0)
|
if (_tcslen(fileType) == 0)
|
||||||
/* if the equal sign is the last character
|
/* if the equal sign is the last character
|
||||||
|
@ -237,7 +228,7 @@ INT CommandAssoc (LPTSTR param)
|
||||||
else
|
else
|
||||||
/* otherwise, add the key and print out the association*/
|
/* otherwise, add the key and print out the association*/
|
||||||
{
|
{
|
||||||
AddAssociation( extension, fileType);
|
AddAssociation(extension, fileType);
|
||||||
PrintAssociation(extension);
|
PrintAssociation(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +239,7 @@ INT CommandAssoc (LPTSTR param)
|
||||||
/* no equal sign, print all associations */
|
/* no equal sign, print all associations */
|
||||||
INT retval = PrintAssociation(param);
|
INT retval = PrintAssociation(param);
|
||||||
|
|
||||||
if (retval == 0) /* if nothing printed out */
|
if (retval == 0) /* if nothing printed out */
|
||||||
ConOutResPrintf(STRING_ASSOC_ERROR, param);
|
ConOutResPrintf(STRING_ASSOC_ERROR, param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,13 +110,14 @@ LPTSTR FindArg(TCHAR Char, BOOL *IsParam0)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
|
LPTSTR BatchParams(LPTSTR s1, LPTSTR s2)
|
||||||
{
|
{
|
||||||
LPTSTR dp = (LPTSTR)cmd_alloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
|
LPTSTR dp = (LPTSTR)cmd_alloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
|
||||||
|
|
||||||
/* JPP 20-Jul-1998 added error checking */
|
/* JPP 20-Jul-1998 added error checking */
|
||||||
if (dp == NULL)
|
if (dp == NULL)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for dp!\n");
|
||||||
error_out_of_memory();
|
error_out_of_memory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +159,7 @@ LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
|
||||||
/*
|
/*
|
||||||
* free the allocated memory of a batch file
|
* free the allocated memory of a batch file
|
||||||
*/
|
*/
|
||||||
VOID ClearBatch()
|
VOID ClearBatch(VOID)
|
||||||
{
|
{
|
||||||
TRACE ("ClearBatch mem = %08x free = %d\n", bc->mem, bc->memfree);
|
TRACE ("ClearBatch mem = %08x free = %d\n", bc->mem, bc->memfree);
|
||||||
|
|
||||||
|
@ -182,7 +183,7 @@ VOID ClearBatch()
|
||||||
* message
|
* message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VOID ExitBatch()
|
VOID ExitBatch(VOID)
|
||||||
{
|
{
|
||||||
ClearBatch();
|
ClearBatch();
|
||||||
|
|
||||||
|
@ -234,7 +235,7 @@ void BatchFile2Mem(HANDLE hBatchFile)
|
||||||
* The firstword parameter is the full filename of the batch file.
|
* The firstword parameter is the full filename of the batch file.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
INT Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
INT Batch(LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
BATCH_CONTEXT new;
|
BATCH_CONTEXT new;
|
||||||
LPFOR_CONTEXT saved_fc;
|
LPFOR_CONTEXT saved_fc;
|
||||||
|
@ -396,12 +397,18 @@ VOID AddBatchRedirection(REDIRECTION **RedirList)
|
||||||
* Read a single line from the batch file from the current batch/memory position.
|
* Read a single line from the batch file from the current batch/memory position.
|
||||||
* Almost a copy of FileGetString with same UNICODE handling
|
* Almost a copy of FileGetString with same UNICODE handling
|
||||||
*/
|
*/
|
||||||
BOOL BatchGetString (LPTSTR lpBuffer, INT nBufferLength)
|
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
|
||||||
{
|
{
|
||||||
LPSTR lpString;
|
LPSTR lpString;
|
||||||
INT len = 0;
|
INT len = 0;
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
lpString = cmd_alloc(nBufferLength);
|
lpString = cmd_alloc(nBufferLength);
|
||||||
|
if (!lpString)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for lpString\n");
|
||||||
|
error_out_of_memory();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
lpString = lpBuffer;
|
lpString = lpBuffer;
|
||||||
#endif
|
#endif
|
||||||
|
@ -443,7 +450,7 @@ BOOL BatchGetString (LPTSTR lpBuffer, INT nBufferLength)
|
||||||
*
|
*
|
||||||
* Set eflag to 0 if line is not to be echoed else 1
|
* Set eflag to 0 if line is not to be echoed else 1
|
||||||
*/
|
*/
|
||||||
LPTSTR ReadBatchLine ()
|
LPTSTR ReadBatchLine(VOID)
|
||||||
{
|
{
|
||||||
TRACE ("ReadBatchLine ()\n");
|
TRACE ("ReadBatchLine ()\n");
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,10 @@ extern BOOL bEcho; /* The echo flag */
|
||||||
extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */
|
extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */
|
||||||
|
|
||||||
|
|
||||||
LPTSTR FindArg (TCHAR, BOOL *);
|
LPTSTR FindArg(TCHAR, BOOL *);
|
||||||
LPTSTR BatchParams (LPTSTR, LPTSTR);
|
LPTSTR BatchParams(LPTSTR, LPTSTR);
|
||||||
VOID ExitBatch (VOID);
|
VOID ExitBatch(VOID);
|
||||||
INT Batch (LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *);
|
INT Batch(LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *);
|
||||||
BOOL BatchGetString (LPTSTR lpBuffer, INT nBufferLength);
|
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength);
|
||||||
LPTSTR ReadBatchLine(VOID);
|
LPTSTR ReadBatchLine(VOID);
|
||||||
VOID AddBatchRedirection(REDIRECTION **);
|
VOID AddBatchRedirection(REDIRECTION **);
|
||||||
|
|
|
@ -214,12 +214,12 @@ INT cmd_goto (LPTSTR);
|
||||||
/* Prototypes for HISTORY.C */
|
/* Prototypes for HISTORY.C */
|
||||||
#ifdef FEATURE_HISTORY
|
#ifdef FEATURE_HISTORY
|
||||||
LPCTSTR PeekHistory(INT);
|
LPCTSTR PeekHistory(INT);
|
||||||
VOID History (INT, LPTSTR);/*add entries browse history*/
|
VOID History(INT, LPTSTR);/*add entries browse history*/
|
||||||
VOID History_move_to_bottom(VOID);/*F3*/
|
VOID History_move_to_bottom(VOID);/*F3*/
|
||||||
VOID InitHistory(VOID);
|
VOID InitHistory(VOID);
|
||||||
VOID CleanHistory(VOID);
|
VOID CleanHistory(VOID);
|
||||||
VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
|
VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
|
||||||
INT CommandHistory (LPTSTR param);
|
INT CommandHistory(LPTSTR param);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Prototypes for IF.C */
|
/* Prototypes for IF.C */
|
||||||
|
|
|
@ -245,7 +245,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
|
||||||
#ifdef FEATURE_HISTORY
|
#ifdef FEATURE_HISTORY
|
||||||
/* add to the history */
|
/* add to the history */
|
||||||
if (str[0])
|
if (str[0])
|
||||||
History (0, str);
|
History(0, str);
|
||||||
#endif /*FEATURE_HISTORY*/
|
#endif /*FEATURE_HISTORY*/
|
||||||
str[charcount++] = _T('\n');
|
str[charcount++] = _T('\n');
|
||||||
str[charcount] = _T('\0');
|
str[charcount] = _T('\0');
|
||||||
|
@ -479,7 +479,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
|
||||||
#ifdef FEATURE_HISTORY
|
#ifdef FEATURE_HISTORY
|
||||||
/* add to the history */
|
/* add to the history */
|
||||||
if (str[0])
|
if (str[0])
|
||||||
History (0, str);
|
History(0, str);
|
||||||
#endif
|
#endif
|
||||||
str[charcount++] = _T('\n');
|
str[charcount++] = _T('\n');
|
||||||
str[charcount] = _T('\0');
|
str[charcount] = _T('\0');
|
||||||
|
@ -503,7 +503,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
|
||||||
#ifdef FEATURE_HISTORY
|
#ifdef FEATURE_HISTORY
|
||||||
/* get previous command from buffer */
|
/* get previous command from buffer */
|
||||||
ClearCommandLine (str, maxlen, orgx, orgy);
|
ClearCommandLine (str, maxlen, orgx, orgy);
|
||||||
History (-1, str);
|
History(-1, str);
|
||||||
current = charcount = _tcslen (str);
|
current = charcount = _tcslen (str);
|
||||||
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
|
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
|
||||||
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
|
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
|
||||||
|
@ -516,7 +516,7 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
|
||||||
#ifdef FEATURE_HISTORY
|
#ifdef FEATURE_HISTORY
|
||||||
/* get next command from buffer */
|
/* get next command from buffer */
|
||||||
ClearCommandLine (str, maxlen, orgx, orgy);
|
ClearCommandLine (str, maxlen, orgx, orgy);
|
||||||
History (1, str);
|
History(1, str);
|
||||||
current = charcount = _tcslen (str);
|
current = charcount = _tcslen (str);
|
||||||
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
|
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
|
||||||
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
|
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
|
||||||
|
|
|
@ -1390,7 +1390,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
ptrStartNode = cmd_alloc(sizeof(DIRFINDLISTNODE));
|
ptrStartNode = cmd_alloc(sizeof(DIRFINDLISTNODE));
|
||||||
if (ptrStartNode == NULL)
|
if (ptrStartNode == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for ptrStartNode!\n");
|
WARN("Cannot allocate memory for ptrStartNode!\n");
|
||||||
return 1; /* Error cannot allocate memory for 1st object */
|
return 1; /* Error cannot allocate memory for 1st object */
|
||||||
}
|
}
|
||||||
ptrStartNode->stInfo.ptrHead = NULL;
|
ptrStartNode->stInfo.ptrHead = NULL;
|
||||||
|
@ -1408,7 +1408,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
ptrNextNode->ptrNext = cmd_alloc(sizeof(DIRFINDLISTNODE));
|
ptrNextNode->ptrNext = cmd_alloc(sizeof(DIRFINDLISTNODE));
|
||||||
if (ptrNextNode->ptrNext == NULL)
|
if (ptrNextNode->ptrNext == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
WARN("Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
||||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
FindClose(hSearch);
|
FindClose(hSearch);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1458,7 +1458,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
*ptrCurNode = cmd_alloc(sizeof(DIRFINDSTREAMNODE));
|
*ptrCurNode = cmd_alloc(sizeof(DIRFINDSTREAMNODE));
|
||||||
if (*ptrCurNode == NULL)
|
if (*ptrCurNode == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for *ptrCurNode!\n");
|
WARN("Cannot allocate memory for *ptrCurNode!\n");
|
||||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
FindClose(hStreams);
|
FindClose(hStreams);
|
||||||
FindClose(hSearch);
|
FindClose(hSearch);
|
||||||
|
@ -1512,7 +1512,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
ptrFileArray = cmd_alloc(sizeof(PDIRFINDINFO) * dwCount);
|
ptrFileArray = cmd_alloc(sizeof(PDIRFINDINFO) * dwCount);
|
||||||
if (ptrFileArray == NULL)
|
if (ptrFileArray == NULL)
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for ptrFileArray!\n");
|
WARN("Cannot allocate memory for ptrFileArray!\n");
|
||||||
DirNodeCleanup(ptrStartNode, &dwCount);
|
DirNodeCleanup(ptrStartNode, &dwCount);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,8 @@ PushDirectory (LPTSTR pszPath)
|
||||||
LPDIRENTRY lpDir = cmd_alloc(FIELD_OFFSET(DIRENTRY, szPath[_tcslen(pszPath) + 1]));
|
LPDIRENTRY lpDir = cmd_alloc(FIELD_OFFSET(DIRENTRY, szPath[_tcslen(pszPath) + 1]));
|
||||||
if (!lpDir)
|
if (!lpDir)
|
||||||
{
|
{
|
||||||
error_out_of_memory ();
|
WARN("Cannot allocate memory for lpDir\n");
|
||||||
|
error_out_of_memory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,13 @@ static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
|
||||||
{
|
{
|
||||||
SIZE_T Len = 0;
|
SIZE_T Len = 0;
|
||||||
SIZE_T AllocLen = 1000;
|
SIZE_T AllocLen = 1000;
|
||||||
|
|
||||||
LPTSTR Contents = cmd_alloc(AllocLen * sizeof(TCHAR));
|
LPTSTR Contents = cmd_alloc(AllocLen * sizeof(TCHAR));
|
||||||
if (!Contents)
|
if (!Contents)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Contents!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
while (_fgetts(Buffer, CMDLINE_LENGTH, InputFile))
|
while (_fgetts(Buffer, CMDLINE_LENGTH, InputFile))
|
||||||
{
|
{
|
||||||
|
@ -109,6 +113,7 @@ static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
|
||||||
Contents = cmd_realloc(Contents, (AllocLen *= 2) * sizeof(TCHAR));
|
Contents = cmd_realloc(Contents, (AllocLen *= 2) * sizeof(TCHAR));
|
||||||
if (!Contents)
|
if (!Contents)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot reallocate memory for Contents!\n");
|
||||||
cmd_free(OldContents);
|
cmd_free(OldContents);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +459,7 @@ static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
INT
|
||||||
ExecuteFor(PARSED_COMMAND *Cmd)
|
ExecuteFor(PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
|
TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
|
||||||
|
@ -470,6 +475,7 @@ ExecuteFor(PARSED_COMMAND *Cmd)
|
||||||
lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
|
lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
|
||||||
if (!lpNew)
|
if (!lpNew)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for lpNew!\n");
|
||||||
cmd_free(List);
|
cmd_free(List);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,16 +48,16 @@ typedef struct tagHISTORY
|
||||||
LPTSTR string;
|
LPTSTR string;
|
||||||
} HIST_ENTRY, * LPHIST_ENTRY;
|
} HIST_ENTRY, * LPHIST_ENTRY;
|
||||||
|
|
||||||
static INT size, max_size=100;
|
static INT size, max_size = 100;
|
||||||
|
|
||||||
static LPHIST_ENTRY Top;
|
static LPHIST_ENTRY Top = NULL;
|
||||||
static LPHIST_ENTRY Bottom;
|
static LPHIST_ENTRY Bottom = NULL;
|
||||||
|
|
||||||
static LPHIST_ENTRY curr_ptr=0;
|
static LPHIST_ENTRY curr_ptr = NULL;
|
||||||
|
|
||||||
VOID InitHistory(VOID);
|
VOID InitHistory(VOID);
|
||||||
VOID History_move_to_bottom(VOID);
|
VOID History_move_to_bottom(VOID);
|
||||||
VOID History (INT dir, LPTSTR commandline);
|
VOID History(INT dir, LPTSTR commandline);
|
||||||
VOID CleanHistory(VOID);
|
VOID CleanHistory(VOID);
|
||||||
VOID History_del_current_entry(LPTSTR str);
|
VOID History_del_current_entry(LPTSTR str);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ static VOID add_at_bottom(LPTSTR string);
|
||||||
VOID set_size(INT new_size);
|
VOID set_size(INT new_size);
|
||||||
|
|
||||||
|
|
||||||
INT CommandHistory (LPTSTR param)
|
INT CommandHistory(LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR tmp;
|
LPTSTR tmp;
|
||||||
INT tmp_int;
|
INT tmp_int;
|
||||||
|
@ -120,6 +120,8 @@ INT CommandHistory (LPTSTR param)
|
||||||
|
|
||||||
VOID set_size(INT new_size)
|
VOID set_size(INT new_size)
|
||||||
{
|
{
|
||||||
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
while (new_size<size)
|
while (new_size<size)
|
||||||
del(Top->prev);
|
del(Top->prev);
|
||||||
|
|
||||||
|
@ -129,10 +131,22 @@ VOID set_size(INT new_size)
|
||||||
|
|
||||||
VOID InitHistory(VOID)
|
VOID InitHistory(VOID)
|
||||||
{
|
{
|
||||||
size=0;
|
size = 0;
|
||||||
|
|
||||||
Top = cmd_alloc(sizeof(HIST_ENTRY));
|
Top = cmd_alloc(sizeof(HIST_ENTRY));
|
||||||
|
if (!Top)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Top!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Bottom = cmd_alloc(sizeof(HIST_ENTRY));
|
Bottom = cmd_alloc(sizeof(HIST_ENTRY));
|
||||||
|
if (!Bottom)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Bottom!\n");
|
||||||
|
cmd_free(Top);
|
||||||
|
Top = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Top->prev = Bottom;
|
Top->prev = Bottom;
|
||||||
Top->next = NULL;
|
Top->next = NULL;
|
||||||
|
@ -142,13 +156,15 @@ VOID InitHistory(VOID)
|
||||||
Bottom->next = Top;
|
Bottom->next = Top;
|
||||||
Bottom->string = NULL;
|
Bottom->string = NULL;
|
||||||
|
|
||||||
curr_ptr=Bottom;
|
curr_ptr = Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID CleanHistory(VOID)
|
VOID CleanHistory(VOID)
|
||||||
{
|
{
|
||||||
while (Bottom->next!=Top)
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
|
while (Bottom->next != Top)
|
||||||
del(Bottom->next);
|
del(Bottom->next);
|
||||||
|
|
||||||
cmd_free(Top);
|
cmd_free(Top);
|
||||||
|
@ -160,14 +176,16 @@ VOID History_del_current_entry(LPTSTR str)
|
||||||
{
|
{
|
||||||
LPHIST_ENTRY tmp;
|
LPHIST_ENTRY tmp;
|
||||||
|
|
||||||
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (curr_ptr == Bottom)
|
if (curr_ptr == Bottom)
|
||||||
curr_ptr=Bottom->next;
|
curr_ptr = Bottom->next;
|
||||||
|
|
||||||
if (curr_ptr == Top)
|
if (curr_ptr == Top)
|
||||||
curr_ptr=Top->prev;
|
curr_ptr = Top->prev;
|
||||||
|
|
||||||
|
|
||||||
tmp = curr_ptr;
|
tmp = curr_ptr;
|
||||||
|
@ -180,6 +198,8 @@ VOID History_del_current_entry(LPTSTR str)
|
||||||
static
|
static
|
||||||
VOID del(LPHIST_ENTRY item)
|
VOID del(LPHIST_ENTRY item)
|
||||||
{
|
{
|
||||||
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
if (item==NULL || item==Top || item==Bottom)
|
if (item==NULL || item==Top || item==Bottom)
|
||||||
{
|
{
|
||||||
TRACE ("del in " __FILE__ ": returning\n"
|
TRACE ("del in " __FILE__ ": returning\n"
|
||||||
|
@ -206,8 +226,10 @@ VOID add_at_bottom(LPTSTR string)
|
||||||
{
|
{
|
||||||
LPHIST_ENTRY tmp;
|
LPHIST_ENTRY tmp;
|
||||||
|
|
||||||
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
/*delete first entry if maximum number of entries is reached*/
|
/*delete first entry if maximum number of entries is reached*/
|
||||||
while(size>=max_size)
|
while (size>=max_size)
|
||||||
del(Top->prev);
|
del(Top->prev);
|
||||||
|
|
||||||
while (_istspace(*string))
|
while (_istspace(*string))
|
||||||
|
@ -218,23 +240,37 @@ VOID add_at_bottom(LPTSTR string)
|
||||||
|
|
||||||
/*if new entry is the same than the last do not add it*/
|
/*if new entry is the same than the last do not add it*/
|
||||||
if (size)
|
if (size)
|
||||||
|
{
|
||||||
if (_tcscmp(string,Bottom->next->string)==0)
|
if (_tcscmp(string,Bottom->next->string)==0)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*fill bottom with string, it will become Bottom->next*/
|
/*create new empty Bottom*/
|
||||||
Bottom->string=cmd_alloc((_tcslen(string)+1)*sizeof(TCHAR));
|
tmp = cmd_alloc(sizeof(HIST_ENTRY));
|
||||||
|
if (!tmp)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for new Bottom!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*fill old bottom with string, it will become new Bottom->next*/
|
||||||
|
Bottom->string = cmd_alloc((_tcslen(string)+1)*sizeof(TCHAR));
|
||||||
|
if (!Bottom->string)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Bottom->string!\n");
|
||||||
|
cmd_free(tmp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
_tcscpy(Bottom->string,string);
|
_tcscpy(Bottom->string,string);
|
||||||
|
|
||||||
/*save Bottom value*/
|
tmp->next = Bottom;
|
||||||
tmp=Bottom;
|
tmp->prev = NULL;
|
||||||
|
tmp->string = NULL;
|
||||||
|
|
||||||
/*create new void Bottom*/
|
Bottom->prev = tmp;
|
||||||
Bottom=cmd_alloc(sizeof(HIST_ENTRY));
|
|
||||||
Bottom->next=tmp;
|
|
||||||
Bottom->prev=NULL;
|
|
||||||
Bottom->string=NULL;
|
|
||||||
|
|
||||||
tmp->prev=Bottom;
|
/*save the new Bottom value*/
|
||||||
|
Bottom = tmp;
|
||||||
|
|
||||||
/*set new size*/
|
/*set new size*/
|
||||||
size++;
|
size++;
|
||||||
|
@ -243,13 +279,17 @@ VOID add_at_bottom(LPTSTR string)
|
||||||
|
|
||||||
VOID History_move_to_bottom(VOID)
|
VOID History_move_to_bottom(VOID)
|
||||||
{
|
{
|
||||||
curr_ptr=Bottom;
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
|
curr_ptr = Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPCTSTR PeekHistory(INT dir)
|
LPCTSTR PeekHistory(INT dir)
|
||||||
{
|
{
|
||||||
LPHIST_ENTRY entry = curr_ptr;
|
LPHIST_ENTRY entry = curr_ptr;
|
||||||
|
|
||||||
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
if (dir == 0)
|
if (dir == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -283,12 +323,14 @@ LPCTSTR PeekHistory(INT dir)
|
||||||
return entry->string;
|
return entry->string;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID History (INT dir, LPTSTR commandline)
|
VOID History(INT dir, LPTSTR commandline)
|
||||||
{
|
{
|
||||||
|
ASSERT(Top && Bottom);
|
||||||
|
|
||||||
if (dir==0)
|
if (dir==0)
|
||||||
{
|
{
|
||||||
add_at_bottom(commandline);
|
add_at_bottom(commandline);
|
||||||
curr_ptr=Bottom;
|
curr_ptr = Bottom;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,9 +345,9 @@ VOID History (INT dir, LPTSTR commandline)
|
||||||
if (curr_ptr->next==Top || curr_ptr==Top)
|
if (curr_ptr->next==Top || curr_ptr==Top)
|
||||||
{
|
{
|
||||||
#ifdef WRAP_HISTORY
|
#ifdef WRAP_HISTORY
|
||||||
curr_ptr=Bottom;
|
curr_ptr = Bottom;
|
||||||
#else
|
#else
|
||||||
curr_ptr=Top;
|
curr_ptr = Top;
|
||||||
commandline[0]=_T('\0');
|
commandline[0]=_T('\0');
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
@ -321,15 +363,15 @@ VOID History (INT dir, LPTSTR commandline)
|
||||||
if (curr_ptr->prev==Bottom || curr_ptr==Bottom)
|
if (curr_ptr->prev==Bottom || curr_ptr==Bottom)
|
||||||
{
|
{
|
||||||
#ifdef WRAP_HISTORY
|
#ifdef WRAP_HISTORY
|
||||||
curr_ptr=Top;
|
curr_ptr = Top;
|
||||||
#else
|
#else
|
||||||
curr_ptr=Bottom;
|
curr_ptr = Bottom;
|
||||||
commandline[0]=_T('\0');
|
commandline[0]=_T('\0');
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
curr_ptr=curr_ptr->prev;
|
curr_ptr = curr_ptr->prev;
|
||||||
if (curr_ptr->string)
|
if (curr_ptr->string)
|
||||||
_tcscpy(commandline,curr_ptr->string);
|
_tcscpy(commandline,curr_ptr->string);
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,18 +188,20 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
|
||||||
LPTSTR *oldarg;
|
LPTSTR *oldarg;
|
||||||
|
|
||||||
q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
|
q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
|
||||||
if (NULL == q)
|
if (!q)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for q!\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tcscpy (q, entry);
|
_tcscpy (q, entry);
|
||||||
oldarg = *arg;
|
oldarg = *arg;
|
||||||
*arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
|
*arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
|
||||||
if (NULL == *arg)
|
if (!*arg)
|
||||||
{
|
{
|
||||||
cmd_free (q);
|
WARN("Cannot reallocate memory for arg!\n");
|
||||||
*arg = oldarg;
|
*arg = oldarg;
|
||||||
|
cmd_free (q);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,8 +224,9 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
|
||||||
if (NULL != pathend)
|
if (NULL != pathend)
|
||||||
{
|
{
|
||||||
dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
|
dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
|
||||||
if (NULL == dirpart)
|
if (!dirpart)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for dirpart!\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
memcpy(dirpart, pattern, pathend - pattern + 1);
|
memcpy(dirpart, pattern, pathend - pattern + 1);
|
||||||
|
@ -241,8 +244,9 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
|
||||||
if (NULL != dirpart)
|
if (NULL != dirpart)
|
||||||
{
|
{
|
||||||
fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
|
fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
|
||||||
if (NULL == fullname)
|
if (!fullname)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for fullname!\n");
|
||||||
ok = FALSE;
|
ok = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -286,7 +290,10 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards, BOOL handle_plus)
|
||||||
|
|
||||||
arg = cmd_alloc (sizeof (LPTSTR));
|
arg = cmd_alloc (sizeof (LPTSTR));
|
||||||
if (!arg)
|
if (!arg)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for arg!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
*arg = NULL;
|
*arg = NULL;
|
||||||
|
|
||||||
ac = 0;
|
ac = 0;
|
||||||
|
@ -333,6 +340,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards, BOOL handle_plus)
|
||||||
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
||||||
if (!q)
|
if (!q)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for q!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy (q, start, len * sizeof (TCHAR));
|
memcpy (q, start, len * sizeof (TCHAR));
|
||||||
|
@ -381,7 +389,10 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||||
|
|
||||||
arg = cmd_alloc (sizeof (LPTSTR));
|
arg = cmd_alloc (sizeof (LPTSTR));
|
||||||
if (!arg)
|
if (!arg)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for arg!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
*arg = NULL;
|
*arg = NULL;
|
||||||
|
|
||||||
ac = 0;
|
ac = 0;
|
||||||
|
@ -409,6 +420,7 @@ LPTSTR *splitspace (LPTSTR s, LPINT args)
|
||||||
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
||||||
if (!q)
|
if (!q)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for q!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy (q, start, len * sizeof (TCHAR));
|
memcpy (q, start, len * sizeof (TCHAR));
|
||||||
|
|
|
@ -60,7 +60,7 @@ static TCHAR ParseChar(void)
|
||||||
TCHAR Char;
|
TCHAR Char;
|
||||||
|
|
||||||
if (bParseError)
|
if (bParseError)
|
||||||
return CurChar = 0;
|
return (CurChar = 0);
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
/*
|
/*
|
||||||
|
@ -90,7 +90,7 @@ restart:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CurChar = Char;
|
return (CurChar = Char);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ParseError(void)
|
static void ParseError(void)
|
||||||
|
@ -272,6 +272,11 @@ static BOOL ParseRedirection(REDIRECTION **List)
|
||||||
}
|
}
|
||||||
|
|
||||||
Redir = cmd_alloc(FIELD_OFFSET(REDIRECTION, Filename[_tcslen(Tok) + 1]));
|
Redir = cmd_alloc(FIELD_OFFSET(REDIRECTION, Filename[_tcslen(Tok) + 1]));
|
||||||
|
if (!Redir)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Redir!\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
Redir->Next = NULL;
|
Redir->Next = NULL;
|
||||||
Redir->OldHandle = INVALID_HANDLE_VALUE;
|
Redir->OldHandle = INVALID_HANDLE_VALUE;
|
||||||
Redir->Number = Number;
|
Redir->Number = Number;
|
||||||
|
@ -293,7 +298,15 @@ static PARSED_COMMAND *ParseCommandOp(int OpType);
|
||||||
static PARSED_COMMAND *ParseBlock(REDIRECTION *RedirList)
|
static PARSED_COMMAND *ParseBlock(REDIRECTION *RedirList)
|
||||||
{
|
{
|
||||||
PARSED_COMMAND *Cmd, *Sub, **NextPtr;
|
PARSED_COMMAND *Cmd, *Sub, **NextPtr;
|
||||||
|
|
||||||
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
||||||
|
if (!Cmd)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Cmd!\n");
|
||||||
|
ParseError();
|
||||||
|
FreeRedirection(RedirList);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Cmd->Type = C_BLOCK;
|
Cmd->Type = C_BLOCK;
|
||||||
Cmd->Next = NULL;
|
Cmd->Next = NULL;
|
||||||
Cmd->Subcommands = NULL;
|
Cmd->Subcommands = NULL;
|
||||||
|
@ -340,8 +353,16 @@ static PARSED_COMMAND *ParseBlock(REDIRECTION *RedirList)
|
||||||
/* Parse an IF statement */
|
/* Parse an IF statement */
|
||||||
static PARSED_COMMAND *ParseIf(void)
|
static PARSED_COMMAND *ParseIf(void)
|
||||||
{
|
{
|
||||||
PARSED_COMMAND *Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
|
||||||
int Type;
|
int Type;
|
||||||
|
PARSED_COMMAND *Cmd;
|
||||||
|
|
||||||
|
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
||||||
|
if (!Cmd)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Cmd!\n");
|
||||||
|
ParseError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memset(Cmd, 0, sizeof(PARSED_COMMAND));
|
memset(Cmd, 0, sizeof(PARSED_COMMAND));
|
||||||
Cmd->Type = C_IF;
|
Cmd->Type = C_IF;
|
||||||
|
|
||||||
|
@ -432,10 +453,17 @@ condition_done:
|
||||||
*/
|
*/
|
||||||
static PARSED_COMMAND *ParseFor(void)
|
static PARSED_COMMAND *ParseFor(void)
|
||||||
{
|
{
|
||||||
PARSED_COMMAND *Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
PARSED_COMMAND *Cmd;
|
||||||
TCHAR List[CMDLINE_LENGTH];
|
TCHAR List[CMDLINE_LENGTH];
|
||||||
TCHAR *Pos = List;
|
TCHAR *Pos = List;
|
||||||
|
|
||||||
|
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
||||||
|
if (!Cmd)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Cmd!\n");
|
||||||
|
ParseError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memset(Cmd, 0, sizeof(PARSED_COMMAND));
|
memset(Cmd, 0, sizeof(PARSED_COMMAND));
|
||||||
Cmd->Type = C_FOR;
|
Cmd->Type = C_FOR;
|
||||||
|
|
||||||
|
@ -609,6 +637,13 @@ static DECLSPEC_NOINLINE PARSED_COMMAND *ParseCommandPart(REDIRECTION *RedirList
|
||||||
*Pos++ = _T('\0');
|
*Pos++ = _T('\0');
|
||||||
|
|
||||||
Cmd = cmd_alloc(FIELD_OFFSET(PARSED_COMMAND, Command.First[Pos - ParsedLine]));
|
Cmd = cmd_alloc(FIELD_OFFSET(PARSED_COMMAND, Command.First[Pos - ParsedLine]));
|
||||||
|
if (!Cmd)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Cmd!\n");
|
||||||
|
ParseError();
|
||||||
|
FreeRedirection(RedirList);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Cmd->Type = C_COMMAND;
|
Cmd->Type = C_COMMAND;
|
||||||
Cmd->Next = NULL;
|
Cmd->Next = NULL;
|
||||||
Cmd->Subcommands = NULL;
|
Cmd->Subcommands = NULL;
|
||||||
|
@ -647,6 +682,12 @@ static PARSED_COMMAND *ParsePrimary(void)
|
||||||
PARSED_COMMAND *Cmd;
|
PARSED_COMMAND *Cmd;
|
||||||
ParseChar();
|
ParseChar();
|
||||||
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
||||||
|
if (!Cmd)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Cmd!\n");
|
||||||
|
ParseError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Cmd->Type = C_QUIET;
|
Cmd->Type = C_QUIET;
|
||||||
Cmd->Next = NULL;
|
Cmd->Next = NULL;
|
||||||
/* @ acts like a unary operator with low precedence,
|
/* @ acts like a unary operator with low precedence,
|
||||||
|
@ -702,6 +743,14 @@ static PARSED_COMMAND *ParseCommandOp(int OpType)
|
||||||
}
|
}
|
||||||
|
|
||||||
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
Cmd = cmd_alloc(sizeof(PARSED_COMMAND));
|
||||||
|
if (!Cmd)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for Cmd!\n");
|
||||||
|
ParseError();
|
||||||
|
FreeCommand(Left);
|
||||||
|
FreeCommand(Right);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Cmd->Type = OpType;
|
Cmd->Type = OpType;
|
||||||
Cmd->Next = NULL;
|
Cmd->Next = NULL;
|
||||||
Cmd->Redirections = NULL;
|
Cmd->Redirections = NULL;
|
||||||
|
@ -840,8 +889,10 @@ EchoCommand(PARSED_COMMAND *Cmd)
|
||||||
for (Redir = Cmd->Redirections; Redir; Redir = Redir->Next)
|
for (Redir = Cmd->Redirections; Redir; Redir = Redir->Next)
|
||||||
{
|
{
|
||||||
if (SubstituteForVars(Redir->Filename, Buf))
|
if (SubstituteForVars(Redir->Filename, Buf))
|
||||||
|
{
|
||||||
ConOutPrintf(_T(" %c%s%s"), _T('0') + Redir->Number,
|
ConOutPrintf(_T(" %c%s%s"), _T('0') + Redir->Number,
|
||||||
RedirString[Redir->Mode], Buf);
|
RedirString[Redir->Mode], Buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,19 +913,27 @@ Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd)
|
||||||
* overflowing the supplied buffer, define some helper macros to make
|
* overflowing the supplied buffer, define some helper macros to make
|
||||||
* this less painful.
|
* this less painful.
|
||||||
*/
|
*/
|
||||||
#define CHAR(Char) { \
|
#define CHAR(Char) \
|
||||||
|
do { \
|
||||||
if (Out == OutEnd) return NULL; \
|
if (Out == OutEnd) return NULL; \
|
||||||
*Out++ = Char; }
|
*Out++ = Char; \
|
||||||
#define STRING(String) { \
|
} while (0)
|
||||||
|
#define STRING(String) \
|
||||||
|
do { \
|
||||||
if (Out + _tcslen(String) > OutEnd) return NULL; \
|
if (Out + _tcslen(String) > OutEnd) return NULL; \
|
||||||
Out = _stpcpy(Out, String); }
|
Out = _stpcpy(Out, String); \
|
||||||
#define PRINTF(Format, ...) { \
|
} while (0)
|
||||||
|
#define PRINTF(Format, ...) \
|
||||||
|
do { \
|
||||||
UINT Len = _sntprintf(Out, OutEnd - Out, Format, __VA_ARGS__); \
|
UINT Len = _sntprintf(Out, OutEnd - Out, Format, __VA_ARGS__); \
|
||||||
if (Len > (UINT)(OutEnd - Out)) return NULL; \
|
if (Len > (UINT)(OutEnd - Out)) return NULL; \
|
||||||
Out += Len; }
|
Out += Len; \
|
||||||
#define RECURSE(Subcommand) { \
|
} while (0)
|
||||||
|
#define RECURSE(Subcommand) \
|
||||||
|
do { \
|
||||||
Out = Unparse(Subcommand, Out, OutEnd); \
|
Out = Unparse(Subcommand, Out, OutEnd); \
|
||||||
if (!Out) return NULL; }
|
if (!Out) return NULL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
switch (Cmd->Type)
|
switch (Cmd->Type)
|
||||||
{
|
{
|
||||||
|
@ -883,70 +942,71 @@ Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd)
|
||||||
* Windows doesn't bother escaping them, so for compatibility
|
* Windows doesn't bother escaping them, so for compatibility
|
||||||
* we probably shouldn't do it either */
|
* we probably shouldn't do it either */
|
||||||
if (!SubstituteForVars(Cmd->Command.First, Buf)) return NULL;
|
if (!SubstituteForVars(Cmd->Command.First, Buf)) return NULL;
|
||||||
STRING(Buf)
|
STRING(Buf);
|
||||||
if (!SubstituteForVars(Cmd->Command.Rest, Buf)) return NULL;
|
if (!SubstituteForVars(Cmd->Command.Rest, Buf)) return NULL;
|
||||||
STRING(Buf)
|
STRING(Buf);
|
||||||
break;
|
break;
|
||||||
case C_QUIET:
|
case C_QUIET:
|
||||||
CHAR(_T('@'))
|
CHAR(_T('@'));
|
||||||
RECURSE(Cmd->Subcommands)
|
RECURSE(Cmd->Subcommands);
|
||||||
break;
|
break;
|
||||||
case C_BLOCK:
|
case C_BLOCK:
|
||||||
CHAR(_T('('))
|
CHAR(_T('('));
|
||||||
for (Sub = Cmd->Subcommands; Sub; Sub = Sub->Next)
|
for (Sub = Cmd->Subcommands; Sub; Sub = Sub->Next)
|
||||||
{
|
{
|
||||||
RECURSE(Sub)
|
RECURSE(Sub);
|
||||||
if (Sub->Next)
|
if (Sub->Next)
|
||||||
CHAR(_T('&'))
|
CHAR(_T('&'));
|
||||||
}
|
}
|
||||||
CHAR(_T(')'))
|
CHAR(_T(')'));
|
||||||
break;
|
break;
|
||||||
case C_MULTI:
|
case C_MULTI:
|
||||||
case C_IFFAILURE:
|
case C_IFFAILURE:
|
||||||
case C_IFSUCCESS:
|
case C_IFSUCCESS:
|
||||||
case C_PIPE:
|
case C_PIPE:
|
||||||
Sub = Cmd->Subcommands;
|
Sub = Cmd->Subcommands;
|
||||||
RECURSE(Sub)
|
RECURSE(Sub);
|
||||||
PRINTF(_T(" %s "), OpString[Cmd->Type - C_OP_LOWEST])
|
PRINTF(_T(" %s "), OpString[Cmd->Type - C_OP_LOWEST]);
|
||||||
RECURSE(Sub->Next)
|
RECURSE(Sub->Next);
|
||||||
break;
|
break;
|
||||||
case C_IF:
|
case C_IF:
|
||||||
STRING(_T("if"))
|
STRING(_T("if"));
|
||||||
if (Cmd->If.Flags & IFFLAG_IGNORECASE)
|
if (Cmd->If.Flags & IFFLAG_IGNORECASE)
|
||||||
STRING(_T(" /I"))
|
STRING(_T(" /I"));
|
||||||
if (Cmd->If.Flags & IFFLAG_NEGATE)
|
if (Cmd->If.Flags & IFFLAG_NEGATE)
|
||||||
STRING(_T(" not"))
|
STRING(_T(" not"));
|
||||||
if (Cmd->If.LeftArg && SubstituteForVars(Cmd->If.LeftArg, Buf))
|
if (Cmd->If.LeftArg && SubstituteForVars(Cmd->If.LeftArg, Buf))
|
||||||
PRINTF(_T(" %s"), Buf)
|
PRINTF(_T(" %s"), Buf);
|
||||||
PRINTF(_T(" %s"), IfOperatorString[Cmd->If.Operator]);
|
PRINTF(_T(" %s"), IfOperatorString[Cmd->If.Operator]);
|
||||||
if (!SubstituteForVars(Cmd->If.RightArg, Buf)) return NULL;
|
if (!SubstituteForVars(Cmd->If.RightArg, Buf)) return NULL;
|
||||||
PRINTF(_T(" %s "), Buf)
|
PRINTF(_T(" %s "), Buf);
|
||||||
Sub = Cmd->Subcommands;
|
Sub = Cmd->Subcommands;
|
||||||
RECURSE(Sub)
|
RECURSE(Sub);
|
||||||
if (Sub->Next)
|
if (Sub->Next)
|
||||||
{
|
{
|
||||||
STRING(_T(" else "))
|
STRING(_T(" else "));
|
||||||
RECURSE(Sub->Next)
|
RECURSE(Sub->Next);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case C_FOR:
|
case C_FOR:
|
||||||
STRING(_T("for"))
|
STRING(_T("for"));
|
||||||
if (Cmd->For.Switches & FOR_DIRS) STRING(_T(" /D"))
|
if (Cmd->For.Switches & FOR_DIRS) STRING(_T(" /D"));
|
||||||
if (Cmd->For.Switches & FOR_F) STRING(_T(" /F"))
|
if (Cmd->For.Switches & FOR_F) STRING(_T(" /F"));
|
||||||
if (Cmd->For.Switches & FOR_LOOP) STRING(_T(" /L"))
|
if (Cmd->For.Switches & FOR_LOOP) STRING(_T(" /L"));
|
||||||
if (Cmd->For.Switches & FOR_RECURSIVE) STRING(_T(" /R"))
|
if (Cmd->For.Switches & FOR_RECURSIVE) STRING(_T(" /R"));
|
||||||
if (Cmd->For.Params)
|
if (Cmd->For.Params)
|
||||||
PRINTF(_T(" %s"), Cmd->For.Params)
|
PRINTF(_T(" %s"), Cmd->For.Params);
|
||||||
PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List)
|
PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List);
|
||||||
RECURSE(Cmd->Subcommands)
|
RECURSE(Cmd->Subcommands);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Redir = Cmd->Redirections; Redir; Redir = Redir->Next)
|
for (Redir = Cmd->Redirections; Redir; Redir = Redir->Next)
|
||||||
{
|
{
|
||||||
if (!SubstituteForVars(Redir->Filename, Buf)) return NULL;
|
if (!SubstituteForVars(Redir->Filename, Buf))
|
||||||
|
return NULL;
|
||||||
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
|
PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
|
||||||
RedirString[Redir->Mode], Buf)
|
RedirString[Redir->Mode], Buf);
|
||||||
}
|
}
|
||||||
return Out;
|
return Out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,12 @@ INT cmd_path (LPTSTR param)
|
||||||
LPTSTR pszBuffer;
|
LPTSTR pszBuffer;
|
||||||
|
|
||||||
pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||||
|
if (!pszBuffer)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for pszBuffer!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
|
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
|
||||||
if (dwBuffer == 0)
|
if (dwBuffer == 0)
|
||||||
{
|
{
|
||||||
|
@ -61,8 +67,9 @@ INT cmd_path (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR pszOldBuffer = pszBuffer;
|
LPTSTR pszOldBuffer = pszBuffer;
|
||||||
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
|
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
|
||||||
if (pszBuffer == NULL)
|
if (!pszBuffer)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot reallocate memory for pszBuffer!\n");
|
||||||
cmd_free(pszOldBuffer);
|
cmd_free(pszOldBuffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ INT cmd_setlocal(LPTSTR param)
|
||||||
Saved = cmd_alloc(sizeof(SETLOCAL));
|
Saved = cmd_alloc(sizeof(SETLOCAL));
|
||||||
if (!Saved)
|
if (!Saved)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for Saved!\n");
|
||||||
error_out_of_memory();
|
error_out_of_memory();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,8 +178,9 @@ INT cmd_start (LPTSTR Rest)
|
||||||
|
|
||||||
/* get comspec */
|
/* get comspec */
|
||||||
comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
|
comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
|
||||||
if (comspec == NULL)
|
if (!comspec)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot allocate memory for start comspec!\n");
|
||||||
error_out_of_memory();
|
error_out_of_memory();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,13 +149,20 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
|
||||||
|
|
||||||
/* load environment variable PATHEXT */
|
/* load environment variable PATHEXT */
|
||||||
pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||||
|
if (!pszPathExt)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for pszPathExt!\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
|
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
|
||||||
if (dwBuffer > ENV_BUFFER_SIZE)
|
if (dwBuffer > ENV_BUFFER_SIZE)
|
||||||
{
|
{
|
||||||
LPTSTR pszOldPathExt = pszPathExt;
|
LPTSTR pszOldPathExt = pszPathExt;
|
||||||
pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
|
pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
|
||||||
if (pszPathExt == NULL)
|
if (!pszPathExt)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot reallocate memory for pszPathExt!\n");
|
||||||
cmd_free(pszOldPathExt);
|
cmd_free(pszOldPathExt);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -187,13 +194,20 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
|
||||||
|
|
||||||
/* load environment variable PATH into buffer */
|
/* load environment variable PATH into buffer */
|
||||||
pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||||
|
if (!pszPath)
|
||||||
|
{
|
||||||
|
WARN("Cannot allocate memory for pszPath!\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
|
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
|
||||||
if (dwBuffer > ENV_BUFFER_SIZE)
|
if (dwBuffer > ENV_BUFFER_SIZE)
|
||||||
{
|
{
|
||||||
LPTSTR pszOldPath = pszPath;
|
LPTSTR pszOldPath = pszPath;
|
||||||
pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
|
pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
|
||||||
if (pszPath == NULL)
|
if (!pszPath)
|
||||||
{
|
{
|
||||||
|
WARN("Cannot reallocate memory for pszPath!\n");
|
||||||
cmd_free(pszOldPath);
|
cmd_free(pszOldPath);
|
||||||
cmd_free(pszPathExt);
|
cmd_free(pszPathExt);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Reference in a new issue