Subject: catgirl: Fix off-by-one edge case in macro expansion (patch)

From: Alcor <[email-masked]>
Date: Mon, 04 May 2026 18:05:12 +0200

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,

>From d0ea31d8bf8f5e5547146adb785f148841db6dfe Mon Sep 17 00:00:00 2001
From: Alcor <[email-masked]>
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