Skip to content

Commit f27e719

Browse files
committed
FIX: Failure when system/script/args > 1022 bytes
Fixes: metaeducation/rebol-issues#2140 (cherry picked from commit 33da799) (cherry picked from commit d637340) (cherry picked from commit cf99471)
1 parent a35168b commit f27e719

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/os/host-args.c

+17-5
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,14 +199,16 @@ const struct arg_chr arg_chars2[] = {
201199
**
202200
***********************************************************************/
203201
{
202+
int arg_buf_size=128;
203+
204204
REBCHR *arg;
205205
REBCHR *args = 0; // holds trailing args
206206
int flag;
207207
int i;
208208

209209
CLEARS(rargs);
210210

211-
// First arg is path to execuable (on most systems):
211+
// First arg is path to executable (on most systems):
212212
if (argc > 0) rargs->exe_path = *argv;
213213

214214
OS_Get_Current_Dir(&rargs->home_dir);
@@ -262,11 +262,23 @@ const struct arg_chr arg_chars2[] = {
262262
rargs->script = arg;
263263
else {
264264
int len;
265+
int size;
266+
REBCHR *tmp;
265267
if (!args) {
266-
args = MAKE_STR(ARG_BUF_SIZE);
268+
args = MAKE_STR(arg_buf_size);
267269
args[0] = 0;
268270
}
269-
len = ARG_BUF_SIZE - LEN_STR(args) - 2; // space remaining
271+
len = LEN_STR(arg) + LEN_STR(args) + 2;
272+
size = arg_buf_size;
273+
while (size < len) size *= 2;
274+
if (size > arg_buf_size) {
275+
tmp = args;
276+
args = MAKE_STR(size);
277+
memcpy(args, tmp, arg_buf_size);
278+
arg_buf_size = size;
279+
free(tmp);
280+
}
281+
len = arg_buf_size - LEN_STR(args) - 2; // space remaining
270282
JOIN_STR(args, arg, len);
271283
JOIN_STR(args, TXT(" "), 1);
272284
}

0 commit comments

Comments
 (0)