shithub: femtolisp

Download patch

ref: 5b498d17047e767e07ff85b662ce03218cf624ed
parent: 8626ed16521ac13ce502d37c649ab9dfff0047a3
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Jan 2 00:37:35 EST 2025

symbol_t: fix the fields ordering vs gensym_t

This has caused issues with bounded comparison, detected by
memory sanitizer as unitialized memory access.
Add a note so it's less tempting to repeat the same mistake.

--- a/flisp.h
+++ b/flisp.h
@@ -57,11 +57,13 @@
 	value_t cdr;
 }cons_t;
 
+// NOTE: symbol_t MUST have the same fields as gensym_t first
+// there are places where gensyms are treated as normal symbols
 typedef struct {
-	const char *name;
-	value_t binding;   // global value binding
 	fltype_t *type;
+	value_t binding;   // global value binding
 	uint32_t hash;
+	const char *name;
 	uint8_t numtype;
 	uint8_t size;
 	uint8_t flags;