Author: hbelusca
Date: Thu Oct 11 00:30:57 2012
New Revision: 57536
URL:
http://svn.reactos.org/svn/reactos?rev=57536&view=rev
Log:
[CRT]
Use a temporary buffer to parse the program's arguments, instead of using (and thus
overwriting) the _a/wcmdln variable.
Fix msvcrt_apitest:CommandLine test.
CORE-6717 #comment Fixed in revision r57536. #resolve
Modified:
trunk/reactos/lib/sdk/crt/misc/getargs.c
Modified: trunk/reactos/lib/sdk/crt/misc/getargs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/misc/getargs.c…
==============================================================================
--- trunk/reactos/lib/sdk/crt/misc/getargs.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/misc/getargs.c [iso-8859-1] Thu Oct 11 00:30:57 2012
@@ -183,6 +183,7 @@
{
int i, afterlastspace, ignorespace, doexpand;
size_t len;
+ char* aNewCmdln;
/* missing threading init */
@@ -203,10 +204,12 @@
len = strlen(_acmdln);
-
- while (_acmdln[i])
- {
- if (_acmdln[i] == '"')
+ /* Allocate a temporary buffer to be used instead of the original _acmdln parameter.
*/
+ aNewCmdln = strndup(_acmdln, len);
+
+ while (aNewCmdln[i])
+ {
+ if (aNewCmdln[i] == '"')
{
if(ignorespace)
{
@@ -217,16 +220,16 @@
ignorespace = 1;
doexpand = 0;
}
- memmove(_acmdln + i, _acmdln + i + 1, len - i);
+ memmove(aNewCmdln + i, aNewCmdln + i + 1, len - i);
len--;
continue;
}
- if (_acmdln[i] == ' ' && !ignorespace)
- {
- aexpand(strndup(_acmdln + afterlastspace, i - afterlastspace), doexpand);
+ if (aNewCmdln[i] == ' ' && !ignorespace)
+ {
+ aexpand(strndup(aNewCmdln + afterlastspace, i - afterlastspace), doexpand);
i++;
- while (_acmdln[i]==' ')
+ while (aNewCmdln[i] == ' ')
i++;
afterlastspace=i;
doexpand = expand_wildcards;
@@ -237,10 +240,13 @@
}
}
- if (_acmdln[afterlastspace] != 0)
- {
- aexpand(strndup(_acmdln+afterlastspace, i - afterlastspace), doexpand);
- }
+ if (aNewCmdln[afterlastspace] != 0)
+ {
+ aexpand(strndup(aNewCmdln + afterlastspace, i - afterlastspace), doexpand);
+ }
+
+ /* Free the temporary buffer. */
+ free(aNewCmdln);
HeapValidate(GetProcessHeap(), 0, NULL);
@@ -265,6 +271,7 @@
{
int i, afterlastspace, ignorespace, doexpand;
size_t len;
+ wchar_t* wNewCmdln;
/* missing threading init */
@@ -285,9 +292,12 @@
len = wcslen(_wcmdln);
- while (_wcmdln[i])
- {
- if (_wcmdln[i] == L'"')
+ /* Allocate a temporary buffer to be used instead of the original _wcmdln parameter.
*/
+ wNewCmdln = wcsndup(_wcmdln, len);
+
+ while (wNewCmdln[i])
+ {
+ if (wNewCmdln[i] == L'"')
{
if(ignorespace)
{
@@ -298,16 +308,16 @@
ignorespace = 1;
doexpand = 0;
}
- memmove(_wcmdln + i, _wcmdln + i + 1, (len - i) * sizeof(wchar_t));
+ memmove(wNewCmdln + i, wNewCmdln + i + 1, (len - i) * sizeof(wchar_t));
len--;
continue;
}
- if (_wcmdln[i] == L' ' && !ignorespace)
- {
- wexpand(wcsndup(_wcmdln + afterlastspace, i - afterlastspace), doexpand);
+ if (wNewCmdln[i] == L' ' && !ignorespace)
+ {
+ wexpand(wcsndup(wNewCmdln + afterlastspace, i - afterlastspace), doexpand);
i++;
- while (_wcmdln[i]==L' ')
+ while (wNewCmdln[i] == L' ')
i++;
afterlastspace=i;
doexpand = expand_wildcards;
@@ -318,10 +328,13 @@
}
}
- if (_wcmdln[afterlastspace] != 0)
- {
- wexpand(wcsndup(_wcmdln+afterlastspace, i - afterlastspace), doexpand);
- }
+ if (wNewCmdln[afterlastspace] != 0)
+ {
+ wexpand(wcsndup(wNewCmdln + afterlastspace, i - afterlastspace), doexpand);
+ }
+
+ /* Free the temporary buffer. */
+ free(wNewCmdln);
HeapValidate(GetProcessHeap(), 0, NULL);