Began working on a few bugs, thanks /u/skeeto!

This commit is contained in:
2023-01-15 20:30:17 +00:00
parent aeecfabbbc
commit 68ed39fc45
5 changed files with 22 additions and 6 deletions

View File

@@ -15,5 +15,7 @@ jobs:
- uses: actions/checkout@v3
- name: install valgrind
run: sudo apt install valgrind
- name: make test
- name: make test (valgrind)
run: make test
- name: make test (sanitized)
run: make test-sanitized

View File

@@ -1,5 +1,6 @@
# Optimisation Options
# export CFLAGS+=-O2 -mtune=native -march=native
# export CFLAGS+=-fsanitize=address,undefined
export TOY_OUTDIR = out
@@ -35,6 +36,12 @@ static-release: $(TOY_OUTDIR)
test: clean $(TOY_OUTDIR)
$(MAKE) -C test
test-sanitized: export CFLAGS+=-fsanitize=address,undefined
test-sanitized: export LIBS+=-static-libasan
test-sanitized: export DISABLE_VALGRIND=true
test-sanitized: clean $(TOY_OUTDIR)
$(MAKE) -C test
$(TOY_OUTDIR):
mkdir $(TOY_OUTDIR)

View File

@@ -30,7 +30,11 @@ void repl() {
for(;;) {
printf("> ");
fgets(input, size, stdin);
//handle EOF for exits
if (!fgets(input, size, stdin)) {
break;
}
//escape the repl (length of 5 to accomodate the newline)
if (strlen(input) == 5 && (!strncmp(input, "exit", 4) || !strncmp(input, "quit", 4))) {

View File

@@ -180,19 +180,22 @@ static unsigned char readByte(unsigned char* tb, int* count) {
}
static unsigned short readShort(unsigned char* tb, int* count) {
unsigned short ret = *(unsigned short*)(tb + *count);
unsigned short ret = 0;
memcpy(&ret, tb + *count, 2);
*count += 2;
return ret;
}
static int readInt(unsigned char* tb, int* count) {
int ret = *(int*)(tb + *count);
int ret = 0;
memcpy(&ret, tb + *count, 4);
*count += 4;
return ret;
}
static float readFloat(unsigned char* tb, int* count) {
float ret = *(float*)(tb + *count);
float ret = 0;
memcpy(&ret, tb + *count, 4);
*count += 4;
return ret;
}

View File

@@ -14,7 +14,7 @@ all: $(OBJ) $(TESTS:%.c=../$(TOY_OUTDIR)/%.exe)
../$(TOY_OUTDIR)/%.exe: $(ODIR)/%.o
@$(CC) -o $@ $< $(TARGETS:../source/%.c=$(ODIR)/%.o) $(CFLAGS) $(LIBS)
ifeq ($(shell uname),Linux)
ifeq ($(shell uname)$(DISABLE_VALGRIND),Linux)
valgrind --leak-check=full --track-origins=yes $@
else
$@