jcs
/subtext
/amendments
/519
session: Fix initialization of last_space in session_paginate
If the first character of the message is \r or \n, the subsequent
wrapping was wrong because last_space was still 0. Init it to -1
to properly detect when it's never been set.
jcs made amendment 519 about 1 year ago
--- session.c Wed Aug 2 11:08:24 2023
+++ session.c Wed Aug 2 21:37:22 2023
@@ -598,9 +598,10 @@ size_t
session_paginate(struct session *session, const char *str, size_t len,
size_t first_page_printed)
{
- size_t olen = 0, n, adv, last_space = 0;
+ size_t olen = 0, n, adv;
size_t olines = first_page_printed;
size_t line_len = session->terminal_columns;
+ ssize_t last_space = -1;
short last_input = 0;
while (len && !session->ending) {
@@ -619,7 +620,7 @@ session_paginate(struct session *session, const char *
adv = last_space = n + 1;
}
}
- if (last_space == 0) {
+ if (last_space == -1) {
/* no space, break hard */
last_space = MIN(line_len, len);
adv = last_space;
@@ -627,8 +628,10 @@ session_paginate(struct session *session, const char *
if (len == n)
adv = last_space = len;
- session_output(session, str, last_space);
- olen += last_space;
+ if (last_space > 0) {
+ session_output(session, str, last_space);
+ olen += last_space;
+ }
str += adv;
len -= adv;