[PATCH] Fix style character handling bug

[PATCH] Fix style character handling bug

From: para
Cc: para
In some ncurses implementations[1], waddnstr returns ERR when len is 0.
This happens in styleAdd() whenever there is a sequence of more than 1
style character in a row.

This may result in visual bugs, the most notable of which is being
unable to see the messages that mention you (due to the "\26\3"

In order to properly handle multiple style characters in a row, waddnstr
should only be called when len is greater than 0.

Tested on Alpine Linux, using the official ncurses package.
 window.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/window.c b/window.c
index 00041aa..685c85f 100644
--- a/window.c
+++ b/window.c
@@ -146,7 +146,9 @@ void windowInit(void) {
 static int styleAdd(WINDOW *win, struct Style init, const char *str) {
 	struct Style style = init;
 	while (*str) {
-		size_t len = styleParse(&style, &str);
+		size_t len;
+		if ((len = styleParse(&style, &str)) == 0)
+			continue;
 		wattr_set(win, uiAttr(style), uiPair(style), NULL);
 		if (waddnstr(win, str, len) == ERR)
 			return -1;

Re: [PATCH] Fix style character handling bug

From: june
To: para
thanks, applied