summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-27 11:31:48 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-27 11:31:48 +0000
commitf7fb66bd356454614a4d6a2181f18d8b586418cf (patch)
treebfccae4b1afa2ec81d70998b74870f792f6950f3 /win32
parentab720532ef884a69fbf9dc104b8a113b5a6c9a18 (diff)
* win32/win32.c (rb_w32_spawn): get rid of too huge alloca().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index a287749173..ff8b70d9e6 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -969,6 +969,9 @@ join_argv(char *cmd, char *const *argv, BOOL escape)
#define STRNDUPA(ptr, src, len) \
(((char *)memcpy(((ptr) = ALLOCA_N(char, (len) + 1)), (src), (len)))[len] = 0)
+#define STRNDUPV(ptr, v, src, len) \
+ (((char *)memcpy(((ptr) = ALLOCV((v), (len) + 1)), (src), (len)))[len] = 0)
+
static int
check_spawn_mode(int mode)
{
@@ -1114,6 +1117,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
WCHAR *wcmd, *wshell;
rb_pid_t ret;
VALUE v = 0;
+ VALUE v2 = 0;
if (check_spawn_mode(mode)) return -1;
@@ -1153,14 +1157,14 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
}
if ((unsigned char)*prog == quote) {
len = prog++ - cmd - 1;
- STRNDUPA(p, cmd + 1, len);
+ STRNDUPV(p, v2, cmd + 1, len);
shell = p;
break;
}
if (quote) continue;
if (ISSPACE(*prog) || strchr("<>|*?\"", *prog)) {
len = prog - cmd;
- STRNDUPA(p, cmd, len);
+ STRNDUPV(p, v2, cmd, len);
shell = p;
break;
}
@@ -1176,7 +1180,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
p = fbuf;
}
else if (shell != p && strchr(shell, '/')) {
- STRNDUPA(p, shell, len);
+ STRNDUPV(p, v2, shell, len);
shell = p;
}
if (p) translate_char(p, '/', '\\');
@@ -1198,6 +1202,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
if (v) ALLOCV_END(v);
wshell = shell ? acp_to_wstr(shell, NULL) : NULL;
+ if (v2) ALLOCV_END(v2);
ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL), mode);
free(wshell);