From 4e63ba90ca70d4cbd881af1345acaf591426101b Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Tue, 12 May 2026 15:28:43 +0200 Subject: [PATCH] Amiga: bound BufferQueueChar; move CloseWindow out of Forbid() Make the BufferQueueChar macro bounds-check KbdBuffered against KBDBUFFER internally so the RAWKEY and NEWSIZE 'R'-64 paths can no longer push past the 10-byte queue; widen KbdBuffered to int so the counter cannot wrap silently in the queue-scan loops. In amii_cleanup move kill_nhwindows()/DeleteMsgPort() outside the Forbid()/Permit() pair: CloseWindow can wait on layers.library semaphores on OS 3.x and that is unsafe under Forbid. Keep only the IDCMP-flush loop inside. --- sys/amiga/amiwind.c | 7 ++++--- sys/amiga/winext.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/amiga/amiwind.c b/sys/amiga/amiwind.c index d259d5128..c3c1b3394 100644 --- a/sys/amiga/amiwind.c +++ b/sys/amiga/amiwind.c @@ -19,7 +19,8 @@ static struct Message *GetFMsg(struct MsgPort *); static int BufferGetchar(void); void ProcessMessage(struct IntuiMessage *message); -#define BufferQueueChar(ch) (KbdBuffer[KbdBuffered++] = (ch)) +#define BufferQueueChar(ch) \ + do { if (KbdBuffered < KBDBUFFER) KbdBuffer[KbdBuffered++] = (ch); } while (0) struct Device *ConsoleDevice = NULL; @@ -51,7 +52,7 @@ struct Library *DiskfontBase; #define KBDBUFFER 10 static unsigned char KbdBuffer[KBDBUFFER]; -unsigned char KbdBuffered; +int KbdBuffered; #ifdef HACKFONT @@ -609,10 +610,10 @@ amii_cleanup(void) Forbid(); while (msg = (struct IntuiMessage *) GetMsg(HackPort)) ReplyMsg((struct Message *) msg); + Permit(); kill_nhwindows(1); DeleteMsgPort(HackPort); HackPort = NULL; - Permit(); } /* Close the screen, under v37 or greater it is a pub screen and there may diff --git a/sys/amiga/winext.h b/sys/amiga/winext.h index 0ceff1d6b..adfd83cd6 100644 --- a/sys/amiga/winext.h +++ b/sys/amiga/winext.h @@ -63,7 +63,7 @@ extern struct Menu HackMenu[]; extern struct Menu *MenuStrip; extern struct NewMenu GTHackMenu[]; extern APTR *VisualInfo; -extern unsigned char KbdBuffered; +extern int KbdBuffered; extern struct TextFont *TextsFont; extern struct TextFont *HackFont; extern struct IOStdReq ConsoleIO;