all repos — xyw @ c96add80119b624d5377eafe543c88140559f7af

A minimal virtual machine and assembler for terminals.

Fixed a few bugs related to bounds checking and similar.
h3rald h3rald@h3rald.com
Fri, 13 Feb 2026 07:37:58 +0100
commit

c96add80119b624d5377eafe543c88140559f7af

parent

cf74ea2e46cd7f9ef5d2bdb1a06d2cfb0dd0b95d

3 files changed, 9 insertions(+), 8 deletions(-)

jump to
M xyw.cxyw.c

@@ -33,7 +33,7 @@ int main(int argc, char *argv[])

{ xyw_argc = argc; - for (int i = 1; i < argc; i++) + for (int i = 1; i < argc && i < 32; i++) { xyw_argv[i] = argv[i]; if (flag(argv[i], "debug"))

@@ -79,4 +79,5 @@ }

break; } } + return 0; }
M xywasm.cxywasm.c

@@ -74,7 +74,7 @@ // Tracks whether we are inside a directive or not

static unsigned int directive = 0; // Bytecode to be written -xyw_byte data[0xffff] = {}; +xyw_byte data[0x10000] = {}; // Current write pointer xyw_word ptr = 0;

@@ -708,9 +708,8 @@ }

} break; } - if (length > DIRECTIVE_CONTENT_MAX_LENGTH) + if (length >= DIRECTIVE_CONTENT_MAX_LENGTH - 1) { - token_error("Macro contents too long"); return -1; }

@@ -872,7 +871,7 @@ token_column = ctx->column;

token_started = 1; } ctx->column++; - if (token_length > TOKEN_MAX_LENGTH) + if (token_length >= TOKEN_MAX_LENGTH - 1) { token_error("Token too long"); return TOKEN_END_INVALID;

@@ -938,7 +937,7 @@ return TOKEN_END_INVALID;

} } ctx->column++; - if (token_length > TOKEN_MAX_LENGTH) + if (token_length >= TOKEN_MAX_LENGTH - 1) { token_error("Token too long"); return TOKEN_END_INVALID;

@@ -987,7 +986,7 @@ token_column = ctx->column;

token_started = 1; } ctx->column++; - if (token_length > TOKEN_MAX_LENGTH) + if (token_length >= TOKEN_MAX_LENGTH - 1) { token_error("Token too long"); return TOKEN_END_INVALID;
M xywrun.cxywrun.c

@@ -8,7 +8,7 @@ #include "devices/clock.h"

#include "devices/file.h" #include "devices/beeper.h" -#define MEMORY_SIZE 0xffff +#define MEMORY_SIZE 0x10000 #define STACK_SIZE 0xff #define USER_MEMORY_START 0x000

@@ -89,6 +89,7 @@

//// Helpers to retrieve device number and address within the device static inline int get_device(xyw_word addr) { + if (addr < DEVICE_AREA_START) return -1; return (addr - DEVICE_AREA_START) / 16; }