summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-06-04 22:14:44 -0700
committerJune McEnroe <june@causal.agency>2021-06-05 13:23:23 -0400
commit8d7460859b9f4a74b4d8c19295de4f8d21117f2b (patch)
treeb43b2dcb6eeb86648e3277f03f6c09e628cc4113
parentList windows with /window (diff)
downloadcatgirl-8d7460859b9f4a74b4d8c19295de4f8d21117f2b.tar.gz
catgirl-8d7460859b9f4a74b4d8c19295de4f8d21117f2b.zip
Avoid writing past the end of the status bar
When waddnstr is called with a string that would extend past the
end of the window, the string is truncated, the cursor remains at
the last column, and ERR is returned. If this error is ignored and
the loop continues, the next call to waddnstr overwrites the character
at this column, resulting in a slight visual artifact. When the
window is too small to fit the full status line, it is effectively
truncated by one space on the right, since the string shown for
each channel begins with a space.  Additionally, if the last window
is the current window, the space is shown with a colored background.

To fix this, when waddnstr returns ERR, exit the loop in styleAdd()
early return -1 to propogate this error down to the caller.
-rw-r--r--ui.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ui.c b/ui.c
index 6449e27..81cf125 100644
--- a/ui.c
+++ b/ui.c
@@ -374,14 +374,16 @@ static short stylePair(struct Style style) {
 	return colorPair(Colors[style.fg], Colors[style.bg]);
 }
 
-static void styleAdd(WINDOW *win, const char *str) {
+static int styleAdd(WINDOW *win, const char *str) {
 	struct Style style = StyleDefault;
 	while (*str) {
 		size_t len = styleParse(&style, &str);
 		wattr_set(win, styleAttr(style), stylePair(style), NULL);
-		waddnstr(win, str, len);
+		if (waddnstr(win, str, len) == ERR)
+			return -1;
 		str += len;
 	}
+	return 0;
 }
 
 static void statusUpdate(void) {
@@ -420,7 +422,7 @@ static void statusUpdate(void) {
 		if (window->scroll) {
 			catf(&cat, "~%d ", window->scroll);
 		}
-		styleAdd(status, buf);
+		if (styleAdd(status, buf) < 0) break;
 	}
 	wclrtoeol(status);
 
itle='2022-06-08 09:07:06 -0400'>2022-06-08Add Maiden, Mother, CroneJune McEnroe 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe