Skip to content

Commit 33da799

Browse files
committed
fix ticket 2140
failure on long cmdline
1 parent 25033f8 commit 33da799

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/os/host-args.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include "reb-c.h"
4646
#include "reb-args.h"
4747

48-
#define ARG_BUF_SIZE 1024
49-
5048
extern int OS_Get_Current_Dir(REBCHR **lp);
5149

5250
// REBOL Option --Words:
@@ -201,6 +199,8 @@ const struct arg_chr arg_chars2[] = {
201199
**
202200
***********************************************************************/
203201
{
202+
int ARG_BUF_SIZE=1024;
203+
204204
REBCHR *arg;
205205
REBCHR *args = 0; // holds trailing args
206206
int flag;
@@ -261,12 +261,20 @@ const struct arg_chr arg_chars2[] = {
261261
if (!rargs->script)
262262
rargs->script = arg;
263263
else {
264-
int len;
264+
int len; REBCHR *tmp;
265265
if (!args) {
266266
args = MAKE_STR(ARG_BUF_SIZE);
267267
args[0] = 0;
268268
}
269269
len = ARG_BUF_SIZE - LEN_STR(args) - 2; // space remaining
270+
while (len < 0) {
271+
tmp = args;
272+
args = MAKE_STR(2 * ARG_BUF_SIZE);
273+
memcpy(args, tmp, ARG_BUF_SIZE);
274+
ARG_BUF_SIZE *= 2;
275+
free(tmp);
276+
len = ARG_BUF_SIZE - LEN_STR(args) - 2;
277+
}
270278
JOIN_STR(args, arg, len);
271279
JOIN_STR(args, TXT(" "), 1);
272280
}

0 commit comments

Comments
 (0)