curses: fix "---" separators in ^P output

This one has me baffled, first how/when it happened and then why no
one reported it.  The line
 current_mesg->turn = g.moves;
vanished from mesg_add_line() at some point.  It is visible in diff
context of commit 99ed00012e from March,
2019 but I can't find any commit since that time which removed it.

[I've been using
 git log --no-min-parents --no-max-parents --patch win/curses/cursmesg.c
and then searching within the pager.  Maybe that's flaky, but if so,
things wouldn't be any less strange.]

The missing line resulted in mesg->turn being uninitialized, so when
^P compared consecutive messages to decide whether they were issued on
the same turn, arbitrary junk made them all seem to be from different
turns so "---" got inserted before every message.  I suppose that if
someone uses a malloc that zeroes the memory it hands out, mesg->turn
field would always be 0 and ^P would behave as if all messages were
from the same turn, so not show any "---" separators.  Then players
might not be aware that "---" between groups of messages was intended.

[The messages ought to be grouped by move rather than by turn, but
that's something the core would have to provide.]
This commit is contained in:
PatR
2021-12-22 11:33:35 -08:00
parent 459b1c1c8d
commit 29cadc0452
2 changed files with 10 additions and 4 deletions
+6 -4
View File
@@ -372,13 +372,14 @@ curses_prev_mesg(void)
for (count = 0; count < num_messages; ++count) {
mesg = get_msg_line(do_lifo, count);
if (turn != mesg->turn && count != 0) {
curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0,
A_NORMAL, "---", MENU_ITEMFLAGS_NONE);
if (mesg->turn != turn) {
if (count > 0) /* skip separator for first line */
curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0,
A_NORMAL, "---", MENU_ITEMFLAGS_NONE);
turn = mesg->turn;
}
curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0,
A_NORMAL, mesg->str, MENU_ITEMFLAGS_NONE);
turn = mesg->turn;
}
if (!count)
curses_add_menu(wid, &nul_glyphinfo, &Id, 0, 0,
@@ -787,6 +788,7 @@ mesg_add_line(const char *mline)
current_mesg->str = dupstr(mline);
}
}
current_mesg->turn = g.moves;
if (num_messages == 0) {
/* very first message; set up head */