fix bytearray:insert (#594)

This commit is contained in:
MihailRis 2025-08-23 11:47:35 +03:00 committed by GitHub
parent a46aafa562
commit 25f4c7fbdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -28,3 +28,9 @@ assert(#arr == arr:get_capacity())
arr = Bytearray({0, 2, 7, 1, 16, 75, 25})
assert(arr[6] == 75)
arr:insert(2, {5, 6})
assert(arr[#arr] == 25)
assert(arr[2] == 5)
assert(arr[3] == 6)

View File

@ -71,7 +71,7 @@ local function insert(self, index, b)
if self.size + elems > self.capacity then
grow_buffer(self, elems)
end
for i=self.size, index - 1, -1 do
for i = self.size - 1, index - 1, -1 do
self.bytes[i + elems] = self.bytes[i]
end
if _type(b) == "number" then