From 3d482c6ec506db8ef858c9bec340723ecea1d96c Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Fri, 7 Nov 2025 05:35:09 -0500 Subject: fix overflow in putsna --- vui.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'vui.c') diff --git a/vui.c b/vui.c index caf4654..ffd5800 100644 --- a/vui.c +++ b/vui.c @@ -363,6 +363,7 @@ static inline void vui_outs(const char *s) { static inline void vui_out_flush(void) { fwrite(vui_out, 1, vui_outn, stdout); fflush(stdout); + //write(STDOUT_FILENO, vui_out, vui_outn); #if 0 static unsigned out_frame = 0; FILE *f = fopen("out_log.txt", "a"); @@ -643,7 +644,13 @@ static void utf8_decode(uint32_t *dst, const char *src, unsigned n) { } void vui_putsna(int x, int y, const char *s, unsigned n, VuiAttr a) { + if (x >= (int)COLS) return; if (n > COLS - x) n = COLS - x; + if (x < 0) { + n += x; + x = 0; + } + if (n < 1 || y < 0 || y >= (int)LINES) return; utf8_decode(&CHR(x, y), s, n); for (uint16_t *pa = &ATTR(x, y); n--;) *pa++ = a; } -- cgit v1.2.3