jcs
/subtext
/amendments
/635
chat: Fix corner cases, pass buf as string instead of format
jcs made amendment 635 4 days ago
--- chat.c Sat Dec 6 17:50:01 2025
+++ chat.c Fri Sep 18 22:20:11 2026
@@ -78,17 +78,21 @@ chat_printf_line(struct session *s, short around_bar,
plen += vsnprintf(chat_pbuf + plen, sizeof(chat_pbuf) - plen, format,
ap);
va_end(ap);
+ if (plen >= sizeof(chat_pbuf))
+ plen = sizeof(chat_pbuf) - 1;
pbuf_line = chat_pbuf;
max_llen = s->terminal_columns;
+ if (max_llen < MIN_TERMINAL_COLUMNS)
+ max_llen = MIN_TERMINAL_COLUMNS;
while (plen > 0) {
if (plen > max_llen) {
/* chop at last word boundary */
llen = max_llen;
- while (llen >= 0 && pbuf_line[llen] != ' ')
+ while (llen > 0 && pbuf_line[llen] != ' ')
llen--;
- if (llen == -1)
+ if (llen == 0)
/* no words to break on, hard break */
llen = max_llen;
} else {
@@ -345,15 +349,18 @@ chat_who(struct session *s)
sessions[n]->user && sessions[n]->user->is_sysop ? '@' : ' ',
sessions[n]->chat_username);
+ if (len >= sizeof(chat_tbuf))
+ len = sizeof(chat_tbuf) - 1;
+
if (++printed == 3) {
- chat_printf_line(s, 1, chat_tbuf);
+ chat_printf_line(s, 1, "%s", chat_tbuf);
printed = 0;
len = 0;
}
}
if (printed)
- chat_printf_line(s, 1, chat_tbuf);
+ chat_printf_line(s, 1, "%s", chat_tbuf);
}
void