mirror of
https://github.com/reactos/reactos.git
synced 2025-06-14 16:08:31 +00:00
[SHELL32]
- Port CommandLineToArgvW fixes from Wine. Fixes crash in shell32:shlexec test. svn path=/trunk/; revision=56587
This commit is contained in:
parent
cb383858f1
commit
87fa6c0693
1 changed files with 17 additions and 13 deletions
|
@ -66,26 +66,33 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
|
||||||
LPWSTR cmdline;
|
LPWSTR cmdline;
|
||||||
int in_quotes,bcount;
|
int in_quotes,bcount;
|
||||||
|
|
||||||
|
if(!numargs)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (*lpCmdline==0)
|
if (*lpCmdline==0)
|
||||||
{
|
{
|
||||||
/* Return the path to the executable */
|
/* Return the path to the executable */
|
||||||
DWORD len, size=16;
|
DWORD len, deslen=MAX_PATH, size;
|
||||||
|
|
||||||
argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size);
|
size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
|
if (!(argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size))) return NULL;
|
||||||
|
len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
|
||||||
if (!len)
|
if (!len)
|
||||||
{
|
{
|
||||||
LocalFree(argv);
|
LocalFree(argv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (len < size) break;
|
if (len < deslen) break;
|
||||||
size*=2;
|
deslen*=2;
|
||||||
argv = (LPWSTR *)LocalReAlloc(argv, size, 0);
|
size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
|
||||||
|
LocalFree( argv );
|
||||||
}
|
}
|
||||||
argv[0]=(LPWSTR)(argv+1);
|
argv[0]=(LPWSTR)(argv+1);
|
||||||
if (numargs)
|
|
||||||
*numargs=1;
|
*numargs=1;
|
||||||
|
|
||||||
return argv;
|
return argv;
|
||||||
|
@ -134,10 +141,8 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
|
||||||
* This way the caller can make a single GlobalFree call to free both, as per MSDN.
|
* This way the caller can make a single GlobalFree call to free both, as per MSDN.
|
||||||
*/
|
*/
|
||||||
argv=(LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR));
|
argv=(LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(wcslen(lpCmdline)+1)*sizeof(WCHAR));
|
||||||
|
|
||||||
if (!argv)
|
if (!argv)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cmdline=(LPWSTR)(argv+argc);
|
cmdline=(LPWSTR)(argv+argc);
|
||||||
wcscpy(cmdline, lpCmdline);
|
wcscpy(cmdline, lpCmdline);
|
||||||
|
|
||||||
|
@ -203,7 +208,6 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
|
||||||
*d='\0';
|
*d='\0';
|
||||||
argv[argc++]=arg;
|
argv[argc++]=arg;
|
||||||
}
|
}
|
||||||
if (numargs)
|
|
||||||
*numargs=argc;
|
*numargs=argc;
|
||||||
|
|
||||||
return argv;
|
return argv;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue