cmd: Avoid naming conflicts with the global HeapAlloc wrappers.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2018-11-25 21:56:00 +01:00 committed by Alexandre Julliard
parent 37fce36989
commit 44bda237ed
5 changed files with 34 additions and 38 deletions

View File

@ -257,7 +257,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
const char *p; const char *p;
cp = GetConsoleCP(); cp = GetConsoleCP();
bufA = heap_alloc(noChars); bufA = heap_xalloc(noChars);
/* Save current file position */ /* Save current file position */
filepos.QuadPart = 0; filepos.QuadPart = 0;
@ -508,7 +508,7 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute)
size = GetEnvironmentVariableW(env, NULL, 0); size = GetEnvironmentVariableW(env, NULL, 0);
if (size > 0) { if (size > 0) {
WCHAR *fullpath = heap_alloc(size * sizeof(WCHAR)); WCHAR *fullpath = heap_xalloc(size * sizeof(WCHAR));
if (!fullpath || (GetEnvironmentVariableW(env, fullpath, size) == 0) || if (!fullpath || (GetEnvironmentVariableW(env, fullpath, size) == 0) ||
(SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0)) (SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0))
size = 0; size = 0;

View File

@ -720,7 +720,7 @@ void WCMD_copy(WCHAR * args) {
} }
/* We have found something to process - build a COPY_FILE block to store it */ /* We have found something to process - build a COPY_FILE block to store it */
thiscopy = heap_alloc(sizeof(COPY_FILES)); thiscopy = heap_xalloc(sizeof(COPY_FILES));
WINE_TRACE("Not a switch, but probably a filename/list %s\n", wine_dbgstr_w(thisparam)); WINE_TRACE("Not a switch, but probably a filename/list %s\n", wine_dbgstr_w(thisparam));
thiscopy->concatenate = concatnextfilename; thiscopy->concatenate = concatnextfilename;
@ -731,7 +731,7 @@ void WCMD_copy(WCHAR * args) {
leave space to append \* to the end) , then copy in character by character. Strip off leave space to append \* to the end) , then copy in character by character. Strip off
quotes if we find them. */ quotes if we find them. */
len = strlenW(thisparam) + (sizeof(WCHAR) * 5); /* 5 spare characters, null + \*.* */ len = strlenW(thisparam) + (sizeof(WCHAR) * 5); /* 5 spare characters, null + \*.* */
thiscopy->name = heap_alloc(len*sizeof(WCHAR)); thiscopy->name = heap_xalloc(len*sizeof(WCHAR));
memset(thiscopy->name, 0x00, len); memset(thiscopy->name, 0x00, len);
pos1 = thisparam; pos1 = thisparam;
@ -810,7 +810,7 @@ void WCMD_copy(WCHAR * args) {
strcpyW(destname, dotW); strcpyW(destname, dotW);
strcatW(destname, slashW); strcatW(destname, slashW);
destination = heap_alloc(sizeof(COPY_FILES)); destination = heap_xalloc(sizeof(COPY_FILES));
if (destination == NULL) goto exitreturn; if (destination == NULL) goto exitreturn;
destination->concatenate = FALSE; /* Not used for destination */ destination->concatenate = FALSE; /* Not used for destination */
destination->binarycopy = binarymode; destination->binarycopy = binarymode;
@ -1390,7 +1390,7 @@ static BOOL WCMD_delete_one (const WCHAR *thisArg) {
WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(subParm)); WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(subParm));
/* Allocate memory, add to list */ /* Allocate memory, add to list */
nextDir = heap_alloc(sizeof(DIRECTORY_STACK)); nextDir = heap_xalloc(sizeof(DIRECTORY_STACK));
if (allDirs == NULL) allDirs = nextDir; if (allDirs == NULL) allDirs = nextDir;
if (lastEntry != NULL) lastEntry->next = nextDir; if (lastEntry != NULL) lastEntry->next = nextDir;
lastEntry = nextDir; lastEntry = nextDir;
@ -1476,7 +1476,7 @@ static WCHAR *WCMD_strtrim(const WCHAR *s)
const WCHAR *start = s; const WCHAR *start = s;
WCHAR* result; WCHAR* result;
result = heap_alloc((len + 1) * sizeof(WCHAR)); result = heap_xalloc((len + 1) * sizeof(WCHAR));
while (isspaceW(*start)) start++; while (isspaceW(*start)) start++;
if (*start) { if (*start) {
@ -1787,12 +1787,12 @@ static void WCMD_add_dirstowalk(DIRECTORY_STACK *dirsToWalk) {
(strcmpW(fd.cFileName, dotW) != 0)) (strcmpW(fd.cFileName, dotW) != 0))
{ {
/* Allocate memory, add to list */ /* Allocate memory, add to list */
DIRECTORY_STACK *toWalk = heap_alloc(sizeof(DIRECTORY_STACK)); DIRECTORY_STACK *toWalk = heap_xalloc(sizeof(DIRECTORY_STACK));
WINE_TRACE("(%p->%p)\n", remainingDirs, remainingDirs->next); WINE_TRACE("(%p->%p)\n", remainingDirs, remainingDirs->next);
toWalk->next = remainingDirs->next; toWalk->next = remainingDirs->next;
remainingDirs->next = toWalk; remainingDirs->next = toWalk;
remainingDirs = toWalk; remainingDirs = toWalk;
toWalk->dirName = heap_alloc(sizeof(WCHAR) * (strlenW(dirsToWalk->dirName) + 2 + strlenW(fd.cFileName))); toWalk->dirName = heap_xalloc(sizeof(WCHAR) * (strlenW(dirsToWalk->dirName) + 2 + strlenW(fd.cFileName)));
strcpyW(toWalk->dirName, dirsToWalk->dirName); strcpyW(toWalk->dirName, dirsToWalk->dirName);
strcatW(toWalk->dirName, slashW); strcatW(toWalk->dirName, slashW);
strcatW(toWalk->dirName, fd.cFileName); strcatW(toWalk->dirName, fd.cFileName);
@ -2228,7 +2228,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
/* Set up the list of directories to recurse if we are going to */ /* Set up the list of directories to recurse if we are going to */
} else if (doRecurse) { } else if (doRecurse) {
/* Allocate memory, add to list */ /* Allocate memory, add to list */
dirsToWalk = heap_alloc(sizeof(DIRECTORY_STACK)); dirsToWalk = heap_xalloc(sizeof(DIRECTORY_STACK));
dirsToWalk->next = NULL; dirsToWalk->next = NULL;
dirsToWalk->dirName = heap_strdupW(optionsRoot); dirsToWalk->dirName = heap_strdupW(optionsRoot);
WINE_TRACE("Starting with root directory %s\n", wine_dbgstr_w(dirsToWalk->dirName)); WINE_TRACE("Starting with root directory %s\n", wine_dbgstr_w(dirsToWalk->dirName));
@ -3673,7 +3673,7 @@ static int WCMD_getprecedence(const WCHAR in)
* stack * stack
*/ */
static void WCMD_pushnumber(WCHAR *var, int num, VARSTACK **varstack) { static void WCMD_pushnumber(WCHAR *var, int num, VARSTACK **varstack) {
VARSTACK *thisstack = heap_alloc(sizeof(VARSTACK)); VARSTACK *thisstack = heap_xalloc(sizeof(VARSTACK));
thisstack->isnum = (var == NULL); thisstack->isnum = (var == NULL);
if (var) { if (var) {
thisstack->variable = var; thisstack->variable = var;
@ -3736,7 +3736,7 @@ static int WCMD_popnumber(VARSTACK **varstack) {
* Push an operator onto the supplied stack * Push an operator onto the supplied stack
*/ */
static void WCMD_pushoperator(WCHAR op, int precedence, OPSTACK **opstack) { static void WCMD_pushoperator(WCHAR op, int precedence, OPSTACK **opstack) {
OPSTACK *thisstack = heap_alloc(sizeof(OPSTACK)); OPSTACK *thisstack = heap_xalloc(sizeof(OPSTACK));
thisstack->precedence = precedence; thisstack->precedence = precedence;
thisstack->op = op; thisstack->op = op;
thisstack->next = *opstack; thisstack->next = *opstack;
@ -4206,7 +4206,7 @@ void WCMD_setshow_env (WCHAR *s) {
WCHAR *src,*dst; WCHAR *src,*dst;
/* Remove all quotes before doing any calculations */ /* Remove all quotes before doing any calculations */
thisexpr = heap_alloc((strlenW(s+2)+1) * sizeof(WCHAR)); thisexpr = heap_xalloc((strlenW(s+2)+1) * sizeof(WCHAR));
src = s+2; src = s+2;
dst = thisexpr; dst = thisexpr;
while (*src) { while (*src) {
@ -4407,7 +4407,7 @@ void WCMD_start(WCHAR *args)
GetWindowsDirectoryW( file, MAX_PATH ); GetWindowsDirectoryW( file, MAX_PATH );
strcatW( file, exeW ); strcatW( file, exeW );
cmdline = heap_alloc( (strlenW(file) + strlenW(args) + 8) * sizeof(WCHAR) ); cmdline = heap_xalloc( (strlenW(file) + strlenW(args) + 8) * sizeof(WCHAR) );
strcpyW( cmdline, file ); strcpyW( cmdline, file );
strcatW( cmdline, spaceW ); strcatW( cmdline, spaceW );
cmdline_params = cmdline + strlenW(cmdline); cmdline_params = cmdline + strlenW(cmdline);

View File

@ -203,7 +203,7 @@ static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
ULONG domainLen = MAXSTRING; ULONG domainLen = MAXSTRING;
SID_NAME_USE nameuse; SID_NAME_USE nameuse;
secBuffer = heap_alloc(sizeNeeded * sizeof(BYTE)); secBuffer = heap_xalloc(sizeNeeded * sizeof(BYTE));
/* Get the owners security descriptor */ /* Get the owners security descriptor */
if(!GetFileSecurityW(filename, OWNER_SECURITY_INFORMATION, secBuffer, if(!GetFileSecurityW(filename, OWNER_SECURITY_INFORMATION, secBuffer,
@ -273,7 +273,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
same directory. Note issuing a directory header with no contents same directory. Note issuing a directory header with no contents
mirrors what windows does */ mirrors what windows does */
parms = inputparms; parms = inputparms;
fd = heap_alloc(sizeof(WIN32_FIND_DATAW)); fd = heap_xalloc(sizeof(WIN32_FIND_DATAW));
while (parms && strcmpW(inputparms->dirName, parms->dirName) == 0) { while (parms && strcmpW(inputparms->dirName, parms->dirName) == 0) {
concurrentDirs++; concurrentDirs++;
@ -510,7 +510,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(string)); WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(string));
/* Allocate memory, add to list */ /* Allocate memory, add to list */
thisDir = heap_alloc(sizeof(DIRECTORY_STACK)); thisDir = heap_xalloc(sizeof(DIRECTORY_STACK));
if (dirStack == NULL) dirStack = thisDir; if (dirStack == NULL) dirStack = thisDir;
if (lastEntry != NULL) lastEntry->next = thisDir; if (lastEntry != NULL) lastEntry->next = thisDir;
lastEntry = thisDir; lastEntry = thisDir;
@ -841,7 +841,7 @@ void WCMD_directory (WCHAR *args)
} }
WINE_TRACE("Using path '%s'\n", wine_dbgstr_w(path)); WINE_TRACE("Using path '%s'\n", wine_dbgstr_w(path));
thisEntry = heap_alloc(sizeof(DIRECTORY_STACK)); thisEntry = heap_xalloc(sizeof(DIRECTORY_STACK));
if (fullParms == NULL) fullParms = thisEntry; if (fullParms == NULL) fullParms = thisEntry;
if (prevEntry != NULL) prevEntry->next = thisEntry; if (prevEntry != NULL) prevEntry->next = thisEntry;
prevEntry = thisEntry; prevEntry = thisEntry;
@ -853,11 +853,11 @@ void WCMD_directory (WCHAR *args)
wine_dbgstr_w(drive), wine_dbgstr_w(dir), wine_dbgstr_w(drive), wine_dbgstr_w(dir),
wine_dbgstr_w(fname), wine_dbgstr_w(ext)); wine_dbgstr_w(fname), wine_dbgstr_w(ext));
thisEntry->dirName = heap_alloc(sizeof(WCHAR) * (strlenW(drive)+strlenW(dir)+1)); thisEntry->dirName = heap_xalloc(sizeof(WCHAR) * (strlenW(drive)+strlenW(dir)+1));
strcpyW(thisEntry->dirName, drive); strcpyW(thisEntry->dirName, drive);
strcatW(thisEntry->dirName, dir); strcatW(thisEntry->dirName, dir);
thisEntry->fileName = heap_alloc(sizeof(WCHAR) * (strlenW(fname)+strlenW(ext)+1)); thisEntry->fileName = heap_xalloc(sizeof(WCHAR) * (strlenW(fname)+strlenW(ext)+1));
strcpyW(thisEntry->fileName, fname); strcpyW(thisEntry->fileName, fname);
strcatW(thisEntry->fileName, ext); strcatW(thisEntry->fileName, ext);
@ -867,7 +867,7 @@ void WCMD_directory (WCHAR *args)
/* If just 'dir' entered, a '*' parameter is assumed */ /* If just 'dir' entered, a '*' parameter is assumed */
if (fullParms == NULL) { if (fullParms == NULL) {
WINE_TRACE("Inserting default '*'\n"); WINE_TRACE("Inserting default '*'\n");
fullParms = heap_alloc(sizeof(DIRECTORY_STACK)); fullParms = heap_xalloc(sizeof(DIRECTORY_STACK));
fullParms->next = NULL; fullParms->next = NULL;
fullParms->dirName = heap_strdupW(cwd); fullParms->dirName = heap_strdupW(cwd);
fullParms->fileName = heap_strdupW(starW); fullParms->fileName = heap_strdupW(starW);

View File

@ -28,6 +28,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <wine/heap.h>
#include <wine/unicode.h> #include <wine/unicode.h>
/* msdn specified max for Win XP */ /* msdn specified max for Win XP */
@ -127,12 +128,7 @@ void WCMD_free_commands(CMD_LIST *cmds);
void WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects, void WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
CMD_LIST **cmdList, BOOL retrycall); CMD_LIST **cmdList, BOOL retrycall);
void *heap_alloc(size_t); void *heap_xalloc(size_t);
static inline BOOL heap_free(void *mem)
{
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline WCHAR *heap_strdupW(const WCHAR *str) static inline WCHAR *heap_strdupW(const WCHAR *str)
{ {
@ -142,7 +138,7 @@ static inline WCHAR *heap_strdupW(const WCHAR *str)
size_t size; size_t size;
size = (strlenW(str)+1)*sizeof(WCHAR); size = (strlenW(str)+1)*sizeof(WCHAR);
ret = heap_alloc(size); ret = heap_xalloc(size);
memcpy(ret, str, size); memcpy(ret, str, size);
} }

View File

@ -75,7 +75,7 @@ static char *get_file_buffer(void)
{ {
static char *output_bufA = NULL; static char *output_bufA = NULL;
if (!output_bufA) if (!output_bufA)
output_bufA = heap_alloc(MAX_WRITECONSOLE_SIZE); output_bufA = heap_xalloc(MAX_WRITECONSOLE_SIZE);
return output_bufA; return output_bufA;
} }
@ -438,11 +438,11 @@ static void WCMD_show_prompt (BOOL newLine) {
WCMD_output_asis (out_string); WCMD_output_asis (out_string);
} }
void *heap_alloc(size_t size) void *heap_xalloc(size_t size)
{ {
void *ret; void *ret;
ret = HeapAlloc(GetProcessHeap(), 0, size); ret = heap_alloc(size);
if(!ret) { if(!ret) {
ERR("Out of memory\n"); ERR("Out of memory\n");
ExitProcess(1); ExitProcess(1);
@ -981,7 +981,7 @@ static void init_msvcrt_io_block(STARTUPINFOW* st)
* its new input & output handles) * its new input & output handles)
*/ */
sz = max(sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * 3, st_p.cbReserved2); sz = max(sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * 3, st_p.cbReserved2);
ptr = heap_alloc(sz); ptr = heap_xalloc(sz);
flags = (char*)(ptr + sizeof(unsigned)); flags = (char*)(ptr + sizeof(unsigned));
handles = (HANDLE*)(flags + num * sizeof(char)); handles = (HANDLE*)(flags + num * sizeof(char));
@ -1300,12 +1300,12 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
wine_dbgstr_w(command), cmdList); wine_dbgstr_w(command), cmdList);
/* Move copy of the command onto the heap so it can be expanded */ /* Move copy of the command onto the heap so it can be expanded */
new_cmd = heap_alloc(MAXSTRING * sizeof(WCHAR)); new_cmd = heap_xalloc(MAXSTRING * sizeof(WCHAR));
strcpyW(new_cmd, command); strcpyW(new_cmd, command);
cmd = new_cmd; cmd = new_cmd;
/* Move copy of the redirects onto the heap so it can be expanded */ /* Move copy of the redirects onto the heap so it can be expanded */
new_redir = heap_alloc(MAXSTRING * sizeof(WCHAR)); new_redir = heap_xalloc(MAXSTRING * sizeof(WCHAR));
redir = new_redir; redir = new_redir;
/* Strip leading whitespaces, and a '@' if supplied */ /* Strip leading whitespaces, and a '@' if supplied */
@ -1708,16 +1708,16 @@ static void WCMD_addCommand(WCHAR *command, int *commandLen,
CMD_LIST *thisEntry = NULL; CMD_LIST *thisEntry = NULL;
/* Allocate storage for command */ /* Allocate storage for command */
thisEntry = heap_alloc(sizeof(CMD_LIST)); thisEntry = heap_xalloc(sizeof(CMD_LIST));
/* Copy in the command */ /* Copy in the command */
if (command) { if (command) {
thisEntry->command = heap_alloc((*commandLen+1) * sizeof(WCHAR)); thisEntry->command = heap_xalloc((*commandLen+1) * sizeof(WCHAR));
memcpy(thisEntry->command, command, *commandLen * sizeof(WCHAR)); memcpy(thisEntry->command, command, *commandLen * sizeof(WCHAR));
thisEntry->command[*commandLen] = 0x00; thisEntry->command[*commandLen] = 0x00;
/* Copy in the redirects */ /* Copy in the redirects */
thisEntry->redirects = heap_alloc((*redirLen+1) * sizeof(WCHAR)); thisEntry->redirects = heap_xalloc((*redirLen+1) * sizeof(WCHAR));
memcpy(thisEntry->redirects, redirs, *redirLen * sizeof(WCHAR)); memcpy(thisEntry->redirects, redirs, *redirLen * sizeof(WCHAR));
thisEntry->redirects[*redirLen] = 0x00; thisEntry->redirects[*redirLen] = 0x00;
thisEntry->pipeFile[0] = 0x00; thisEntry->pipeFile[0] = 0x00;
@ -1849,7 +1849,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
/* Allocate working space for a command read from keyboard, file etc */ /* Allocate working space for a command read from keyboard, file etc */
if (!extraSpace) if (!extraSpace)
extraSpace = heap_alloc((MAXSTRING+1) * sizeof(WCHAR)); extraSpace = heap_xalloc((MAXSTRING+1) * sizeof(WCHAR));
if (!extraSpace) if (!extraSpace)
{ {
WINE_ERR("Could not allocate memory for extraSpace\n"); WINE_ERR("Could not allocate memory for extraSpace\n");