return stack_size_max;
}
+static void *lre_bytecode_realloc(void *opaque, void *ptr, size_t size)
+{
+ if (size > (INT32_MAX / 2)) {
+ /* the bytecode cannot be larger than 2G. Leave some slack to
+ avoid some overflows. */
+ return NULL;
+ } else {
+ return lre_realloc(opaque, ptr, size);
+ }
+}
+
/* 'buf' must be a zero terminated UTF-8 string of length buf_len.
Return NULL if error and allocate an error message in *perror_msg,
otherwise the compiled bytecode and its length in plen.
s->total_capture_count = -1;
s->has_named_captures = -1;
- dbuf_init2(&s->byte_code, opaque, lre_realloc);
+ dbuf_init2(&s->byte_code, opaque, lre_bytecode_realloc);
dbuf_init2(&s->group_names, opaque, lre_realloc);
dbuf_put_u16(&s->byte_code, re_flags); /* first element is the flags */
dbuf_init2(s, ctx->rt, (DynBufReallocFunc *)js_realloc_rt);
}
+static void *js_realloc_bytecode_rt(void *opaque, void *ptr, size_t size)
+{
+ JSRuntime *rt = opaque;
+ if (size > (INT32_MAX / 2)) {
+ /* the bytecode cannot be larger than 2G. Leave some slack to
+ avoid some overflows. */
+ return NULL;
+ } else {
+ return rt->mf.js_realloc(&rt->malloc_state, ptr, size);
+ }
+}
+
+static inline void js_dbuf_bytecode_init(JSContext *ctx, DynBuf *s)
+{
+ dbuf_init2(s, ctx->rt, js_realloc_bytecode_rt);
+}
+
static inline int is_digit(int c) {
return c >= '0' && c <= '9';
}
fd->is_eval = is_eval;
fd->is_func_expr = is_func_expr;
- js_dbuf_init(ctx, &fd->byte_code);
+ js_dbuf_bytecode_init(ctx, &fd->byte_code);
fd->last_opcode_pos = -1;
fd->func_name = JS_ATOM_NULL;
fd->var_object_idx = -1;
cc.bc_buf = bc_buf = s->byte_code.buf;
cc.bc_len = bc_len = s->byte_code.size;
- js_dbuf_init(ctx, &bc_out);
+ js_dbuf_bytecode_init(ctx, &bc_out);
/* first pass for runtime checks (must be done before the
variables are created) */
cc.bc_buf = bc_buf = s->byte_code.buf;
cc.bc_len = bc_len = s->byte_code.size;
- js_dbuf_init(ctx, &bc_out);
+ js_dbuf_bytecode_init(ctx, &bc_out);
#if SHORT_OPCODES
if (s->jump_size) {