mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Fixed buffer overflow, bytecode is WIP
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#include "toy_bytecode.h"
|
||||
|
||||
#include "toy_memory.h"
|
||||
#include "toy_routine.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
//utils
|
||||
static void expand(Toy_Bytecode* bc, int amount) {
|
||||
if (bc->count + amount > bc->capacity) {
|
||||
while (bc->count + amount > bc->capacity) {
|
||||
int oldCapacity = bc->capacity;
|
||||
|
||||
bc->capacity = TOY_GROW_CAPACITY(oldCapacity);
|
||||
@@ -21,7 +22,7 @@ static void emitByte(Toy_Bytecode* bc, unsigned char byte) {
|
||||
}
|
||||
|
||||
static void writeModule(Toy_Bytecode* bc, Toy_Ast* ast) {
|
||||
//
|
||||
//TODO: routines
|
||||
}
|
||||
|
||||
//bytecode
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user