Fixed buffer overflow, bytecode is WIP

This commit is contained in:
2024-09-19 19:06:49 +10:00
parent 083ee950dd
commit e35af3d84b
3 changed files with 11 additions and 5 deletions

View File

@@ -6,8 +6,8 @@
#include <string.h>
//utils
static void expand(void** handle, int* capacity, int* count) {
if ((*count) +1 > (*capacity)) {
static void expand(void** handle, int* capacity, int* count, int amount) {
while ((*count) + amount > (*capacity)) {
int oldCapacity = (*capacity);
(*capacity) = TOY_GROW_CAPACITY(oldCapacity);
@@ -16,7 +16,7 @@ static void expand(void** handle, int* capacity, int* count) {
}
static void emitByte(void** handle, int* capacity, int* count, unsigned char byte) {
expand(handle, capacity, count);
expand(handle, capacity, count, 1);
((unsigned char*)(*handle))[(*count)++] = byte;
}