From 3eb44f1f79f1820dcf9394a6fe7ea3caa6895b12 Mon Sep 17 00:00:00 2001 From: "J.-F. Cap" Date: Tue, 26 Feb 2019 00:21:03 +0100 Subject: [PATCH] Fix buffer allocation --- src/core/typedarray.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/typedarray.c b/src/core/typedarray.c index 9c519164..3e5ffac2 100644 --- a/src/core/typedarray.c +++ b/src/core/typedarray.c @@ -83,11 +83,14 @@ static JanetTArrayType get_ta_type_by_name(const uint8_t *name) { - - - static JanetTArrayBuffer *ta_buffer_init(JanetTArrayBuffer *buf, size_t size) { - buf->data = (uint8_t *)calloc(size, sizeof(uint8_t)); + buf->data = NULL; + if (size > 0) { + buf->data = (uint8_t *)calloc(size, sizeof(uint8_t)); + if (buf->data == NULL) { + JANET_OUT_OF_MEMORY; + } + } buf->size = size; #ifdef JANET_BIG_ENDIAN buf->flags = TA_FLAG_BIG_ENDIAN;