Skip to content

Commit cf99471

Browse files
committed
Bug fix and optimization
1 parent d637340 commit cf99471

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/os/host-args.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const struct arg_chr arg_chars2[] = {
199199
**
200200
***********************************************************************/
201201
{
202-
int arg_buf_size=1024;
202+
int arg_buf_size=128;
203203

204204
REBCHR *arg;
205205
REBCHR *args = 0; // holds trailing args
@@ -208,7 +208,7 @@ const struct arg_chr arg_chars2[] = {
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);
@@ -261,20 +261,24 @@ const struct arg_chr arg_chars2[] = {
261261
if (!rargs->script)
262262
rargs->script = arg;
263263
else {
264-
int len; REBCHR *tmp;
264+
int len;
265+
int size;
266+
REBCHR *tmp;
265267
if (!args) {
266268
args = MAKE_STR(arg_buf_size);
267269
args[0] = 0;
268270
}
269-
len = arg_buf_size - LEN_STR(args) - 2; // space remaining
270-
while (len < 0) {
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) {
271275
tmp = args;
272-
args = MAKE_STR(2 * arg_buf_size);
276+
args = MAKE_STR(size);
273277
memcpy(args, tmp, arg_buf_size);
274-
arg_buf_size *= 2;
278+
arg_buf_size = size;
275279
free(tmp);
276-
len = arg_buf_size - LEN_STR(args) - 2;
277280
}
281+
len = arg_buf_size - LEN_STR(args) - 2; // space remaining
278282
JOIN_STR(args, arg, len);
279283
JOIN_STR(args, TXT(" "), 1);
280284
}

0 commit comments

Comments
 (0)