jcs
/subtext
/amendments
/293
chat: Fix session iteration
nsessions is the current number of logged-in sessions, but sessions
is a fixed array so we must go to MAX_SESSIONS to visit each slot.
jcs made amendment 293 about 1 year ago
--- chat.c Sun Nov 20 00:02:40 2022
+++ chat.c Tue Nov 29 21:33:16 2022
@@ -39,8 +39,9 @@ chat_broadcast(struct session *s, char *str)
{
short n;
- for (n = 0; n < nsessions; n++) {
- if (!sessions[n]->chatting)
+ for (n = 0; n < MAX_SESSIONS; n++) {
+ if (sessions[n] == NULL || !sessions[n]->logged_in ||
+ !sessions[n]->chatting)
continue;
if (strcmp(s->chatting_with_node,
sessions[n]->chatting_with_node) != 0)
@@ -315,8 +316,9 @@ chat_who(struct session *s)
short n, printed = 0;
size_t len = 0;
- for (n = 0; n < nsessions; n++) {
- if (!sessions[n]->chatting)
+ for (n = 0; n < MAX_SESSIONS; n++) {
+ if (sessions[n] == NULL || !sessions[n]->logged_in ||
+ !sessions[n]->chatting)
continue;
if (strcmp(s->chatting_with_node,
sessions[n]->chatting_with_node) != 0)