summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-11-07 05:35:09 -0500
committerWormHeamer2025-11-07 05:35:09 -0500
commit3d482c6ec506db8ef858c9bec340723ecea1d96c (patch)
treea0d8f923863185011e714227f3781aa01b4b2b7b
parentc88d28d9dc55f8f33cb2a2e6ffc4dc153de0c425 (diff)
fix overflow in putsna
-rw-r--r--vui.c7
1 files changed, 7 insertions, 0 deletions
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;
}