Skip to content

Commit

Permalink
Use malloc to avoid stack overflow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Nov 1, 2023
1 parent 30a2fa2 commit f4c2577
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions quickjs/qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,21 @@ static int run_from_cell_data(JSContext *ctx, bool enable_fs) {
return err;
}

char buf[buf_size + 1];
char *buf = malloc(buf_size + 1);
err = load_cell_code(buf_size, index, (uint8_t *)buf);
if (err) {
return err;
}

if (enable_fs) {
return run_from_file_system_buf(ctx, buf, buf_size);
err = run_from_file_system_buf(ctx, buf, buf_size);
free(buf);
return err;
} else {
buf[buf_size] = 0;
return eval_buf(ctx, buf, buf_size, "<run_from_file>", 0);
err = eval_buf(ctx, buf, buf_size, "<run_from_file>", 0);
free(buf);
return err;
}
}

Expand All @@ -245,16 +249,21 @@ static int run_from_target(JSContext *ctx, const char *target, bool enable_fs) {
return err;
}

char buf[buf_size + 1];
char *buf = malloc(buf_size + 1);
err = load_cell_code(buf_size, index, (uint8_t *)buf);
if (err) {
return err;
}

if (enable_fs) {
return run_from_file_system_buf(ctx, buf, buf_size);
err = run_from_file_system_buf(ctx, buf, buf_size);
free(buf);
return err;
} else {
buf[buf_size] = 0;
return eval_buf(ctx, buf, buf_size, "<run_from_file>", 0);
err = eval_buf(ctx, buf, buf_size, "<run_from_file>", 0);
free(buf);
return err;
}
}

Expand Down

0 comments on commit f4c2577

Please sign in to comment.