diff --git a/dev/tests/bytearray.lua b/dev/tests/bytearray.lua index 1a12bdeb..432dfbf5 100644 --- a/dev/tests/bytearray.lua +++ b/dev/tests/bytearray.lua @@ -25,3 +25,6 @@ end print(#arr, arr:get_capacity()) arr:trim() assert(#arr == arr:get_capacity()) + +arr = Bytearray({0, 2, 7, 1, 16, 75, 25}) +assert(arr[6] == 75) diff --git a/res/modules/internal/bytearray.lua b/res/modules/internal/bytearray.lua index ab93cfea..457587d5 100644 --- a/res/modules/internal/bytearray.lua +++ b/res/modules/internal/bytearray.lua @@ -179,7 +179,7 @@ local FFIBytearray = { return bytearray_type(buffer, #n, #n) elseif t == "table" then local capacity = math.max(#n, MIN_CAPACITY) - local buffer = malloc(capacity) + local buffer = FFI.cast("unsigned char*", malloc(capacity)) for i=1,#n do buffer[i - 1] = n[i] end