From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alcor To: list@causal.agency Cc: june@causal.agency Subject: catgirl: Fix off-by-one edge case in macro expansion (patch) Date: Mon, 04 May 2026 18:05:12 +0200 Message-ID: <87bjevb1on.fsf@tilde.club> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Steps to reproduce: 1. Connect to any network (I chose OFTC for this) 2. Switch to the NickServ tab, or simply /QUERY NickServ 3. Type \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ and hit ENTER 4. Type \hug then hit C-x Expected result: The macro is expanded. Observed result: The macro is not expanded. Patch / Fix: macroExpand() contains an off-by-one error. `macro' should be decremented before doing the backward scan for the macro escape character in order to ensure that no stale buffer memory is queried instead. Attached is a simple fix. Cheers, --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-fix-off-by-one-error-in-macroExpand.patch >From d0ea31d8bf8f5e5547146adb785f148841db6dfe Mon Sep 17 00:00:00 2001 From: Alcor Date: Mon, 4 May 2026 16:04:30 +0200 Subject: [PATCH 2/5] fix off-by-one error in macroExpand() --- input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/input.c b/input.c index 7e1f9c1..748dca2 100644 --- a/input.c +++ b/input.c @@ -271,8 +271,10 @@ void inputCompletion(void) { static int macroExpand(struct Edit *e) { size_t macro = e->pos; + if (!macro) return 0; + --macro; while (macro && e->buf[macro] != L'\\') macro--; - if (macro == e->pos) return 0; + if (e->buf[macro] != L'\\') return 0; for (size_t i = 0; i < ARRAY_LEN(Macros); ++i) { if (wcslen(Macros[i].name) != e->pos - macro) continue; if (wcsncmp(Macros[i].name, &e->buf[macro], e->pos - macro)) continue; -- 2.47.3 --=-=-=--