Fixed a hash collision causing null variables to be overwritten
Andrew, don't you dare run my code through a clanker again or I'll hunt your Canuck ass down and beat you with a hockey stick.
This commit is contained in:
@@ -172,7 +172,7 @@ static void attr_tableRemove(Toy_VM* vm, Toy_FunctionNative* self) {
|
||||
|
||||
Toy_Value Toy_private_handleTableAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute) {
|
||||
if (MATCH_VALUE_AND_CSTRING(attribute, "length")) {
|
||||
return TOY_VALUE_FROM_INTEGER(TOY_VALUE_AS_ARRAY(compound)->count);
|
||||
return TOY_VALUE_FROM_INTEGER(TOY_VALUE_AS_TABLE(compound)->count);
|
||||
}
|
||||
else if (MATCH_VALUE_AND_CSTRING(attribute, "insert")) {
|
||||
Toy_Function* fn = Toy_createFunctionFromCallback(&vm->memoryBucket, attr_tableInsert);
|
||||
|
||||
@@ -78,6 +78,7 @@ static void emitByte(unsigned char** handle, unsigned int* capacity, unsigned in
|
||||
((unsigned char*)(*handle))[(*count)++] = byte;
|
||||
}
|
||||
|
||||
//BUG: There might be issues here when compiled on big-endian platforms
|
||||
static void emitInt(unsigned char** handle, unsigned int* capacity, unsigned int* count, unsigned int bytes) {
|
||||
char* ptr = (char*)&bytes;
|
||||
emitByte(handle, capacity, count, *(ptr++));
|
||||
@@ -200,8 +201,8 @@ static unsigned int emitParameters(Toy_Bytecode* mb, Toy_Ast* ast) {
|
||||
}
|
||||
|
||||
//the address within the data section
|
||||
char buffer[128];
|
||||
snprintf(buffer, 128, "%.*s", ast->varDeclare.name->info.length, ast->varDeclare.name->leaf.data);
|
||||
char buffer[256];
|
||||
snprintf(buffer, 256, "%.*s", ast->varDeclare.name->info.length, ast->varDeclare.name->leaf.data);
|
||||
unsigned int dataAddr = emitCStringToData(&(mb->data), &(mb->dataCapacity), &(mb->dataCount), buffer);
|
||||
|
||||
//check the param index for that entry i.e. don't reuse parameter names
|
||||
|
||||
+2
-2
@@ -324,7 +324,7 @@ static Toy_AstFlag literal(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_As
|
||||
|
||||
case TOY_TOKEN_LITERAL_INTEGER: {
|
||||
//filter the '_' character
|
||||
char buffer[parser->previous.length];
|
||||
char buffer[parser->previous.length + 1];
|
||||
|
||||
unsigned int i = 0, o = 0;
|
||||
do {
|
||||
@@ -341,7 +341,7 @@ static Toy_AstFlag literal(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_As
|
||||
|
||||
case TOY_TOKEN_LITERAL_FLOAT: {
|
||||
//filter the '_' character
|
||||
char buffer[parser->previous.length];
|
||||
char buffer[parser->previous.length + 1];
|
||||
|
||||
unsigned int i = 0, o = 0;
|
||||
do {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "toy_print.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static Toy_callbackType printCallback = puts;
|
||||
@@ -19,14 +20,17 @@ void Toy_assertFailure(const char* msg) {
|
||||
}
|
||||
|
||||
void Toy_setPrintCallback(Toy_callbackType cb) {
|
||||
assert(cb);
|
||||
printCallback = cb;
|
||||
}
|
||||
|
||||
void Toy_setErrorCallback(Toy_callbackType cb) {
|
||||
assert(cb);
|
||||
errorCallback = cb;
|
||||
}
|
||||
|
||||
void Toy_setAssertFailureCallback(Toy_callbackType cb) {
|
||||
assert(cb);
|
||||
assertCallback = cb;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ static void probeAndInsert(Toy_Scope* scope, Toy_String* key, Toy_Value value, T
|
||||
}
|
||||
|
||||
//if this spot is free, insert and return
|
||||
if (TOY_VALUE_IS_NULL(scope->data[probe].value)) {
|
||||
if (scope->data[probe].key == NULL) { //fuck my life
|
||||
scope->data[probe] = entry;
|
||||
scope->count++;
|
||||
scope->maxPsl = entry.psl > scope->maxPsl ? entry.psl : scope->maxPsl;
|
||||
|
||||
@@ -73,6 +73,8 @@ static void processRead(Toy_VM* vm) {
|
||||
//grab the jump as an integer
|
||||
unsigned int jump = *((int*)(vm->code + vm->jumpsAddr + READ_INT(vm)));
|
||||
|
||||
//BUG: the jump parameter could cause an out of bounds read if it's malformed
|
||||
|
||||
//jumps are relative to the data address
|
||||
char* cstring = (char*)(vm->code + vm->dataAddr + jump);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user