Skip to content

Commit 8132347

Browse files
authored
Throw exception on out of memory in dynamic buffer (#838)
js_dbuf_init users that check the return value of functions like dbuf_put should be able to assume that an OOM exception is pending when the function returns an error. No callers currently do so but I am going to start doing that in the not too distant future. js_dbuf_init takes a JSContext pointer, strongly suggesting it calls js_realloc, but in fact it called js_realloc_rt, which does *not* raise OOM exceptions. Call js_realloc and move js_dbuf_realloc closer to js_dbuf_init for legibility reasons.
1 parent a0ea277 commit 8132347

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

quickjs.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -1518,12 +1518,6 @@ void *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size)
15181518
return ptr;
15191519
}
15201520

1521-
static void *js_dbuf_realloc(void *opaque, void *ptr, size_t size)
1522-
{
1523-
JSRuntime *rt = opaque;
1524-
return js_realloc_rt(rt, ptr, size);
1525-
}
1526-
15271521
size_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr)
15281522
{
15291523
return rt->mf.js_malloc_usable_size(ptr);
@@ -1666,9 +1660,14 @@ static inline int js_resize_array(JSContext *ctx, void **parray, int elem_size,
16661660
return 0;
16671661
}
16681662

1663+
static void *js_dbuf_realloc(void *ctx, void *ptr, size_t size)
1664+
{
1665+
return js_realloc(ctx, ptr, size);
1666+
}
1667+
16691668
static inline void js_dbuf_init(JSContext *ctx, DynBuf *s)
16701669
{
1671-
dbuf_init2(s, ctx->rt, js_dbuf_realloc);
1670+
dbuf_init2(s, ctx, js_dbuf_realloc);
16721671
}
16731672

16741673
static inline int is_digit(int c) {

0 commit comments

Comments
 (0)