diff options
| author | WormHeamer | 2025-11-07 05:35:09 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-11-07 05:35:09 -0500 |
| commit | 3d482c6ec506db8ef858c9bec340723ecea1d96c (patch) | |
| tree | a0d8f923863185011e714227f3781aa01b4b2b7b | |
| parent | c88d28d9dc55f8f33cb2a2e6ffc4dc153de0c425 (diff) | |
fix overflow in putsna
| -rw-r--r-- | vui.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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; } |
