From 8fd323f4d4cad9cee49430e81d3fda2b3c06f309 Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 15:59:28 -0800 Subject: [PATCH 20/24] Font Management: adding a font to an empty list no longer saves a garbage font With no [Font:...] sections, read_font_files() returns NULL and Menu.createFont reallocs from NULL, then memmoves the old terminator -- which does not exist -- into the new end slot. The list's end marker is uninitialised memory: deleting the new font moves it into slot 0, and the next save writes it out as a [Font:] section whose paths are pointer bytes too. Font Management then lists that garbage name. Zero the terminator when the list starts from nothing. --- src/syncterm/wren_bind_menu_fonts.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/syncterm/wren_bind_menu_fonts.c b/src/syncterm/wren_bind_menu_fonts.c index dbbc5606..7b2cc238 100644 --- a/src/syncterm/wren_bind_menu_fonts.c +++ b/src/syncterm/wren_bind_menu_fonts.c @@ -193,6 +193,12 @@ fn_Menu_createFont(WrenVM *vm) wrenSetSlotNull(vm, 0); return; } + /* An empty configuration has no array at all (read_font_files + * returns NULL), so there is no terminator to move: make one, or the + * memmove below shifts an uninitialised entry into the end slot, and + * deleting the new font then saves that garbage as a [Font:...] + * section of pointer bytes. */ + bool fresh = model.fonts == NULL; struct font_files *fonts = realloc(model.fonts, (model.count + 2) * sizeof(*fonts)); if (fonts == NULL) { @@ -200,6 +206,8 @@ fn_Menu_createFont(WrenVM *vm) wrenSetSlotNull(vm, 0); return; } + if (fresh) + memset(&fonts[0], 0, sizeof(fonts[0])); model.fonts = fonts; memmove(&fonts[index + 1], &fonts[index], (model.count - index + 1) * sizeof(*fonts)); -- 2.47.3