Commit 9b546fae authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(adjust_read): Rewritten to fix an obscure bug.

parent 08690b68
/*
* $Id: membership.c,v 0.21 1994/10/22 12:59:30 ceder Exp $
* $Id: membership.c,v 0.22 1994/10/23 16:15:07 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -31,7 +31,7 @@
#define DEBUG_MARK_AS_READ
static char *rcsid = "$Id: membership.c,v 0.21 1994/10/22 12:59:30 ceder Exp $";
static char *rcsid = "$Id: membership.c,v 0.22 1994/10/23 16:15:07 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -300,68 +300,66 @@ static void
adjust_read( Membership * m,
const Conference * conf)
{
unsigned short i;
/* The first HANDLED texts in read_texts in M are already
included in last_text_read. */
unsigned short handled;
unsigned short i;
Local_text_no * locp;
Local_text_no conf_max; /* Highest used local_text_no in conf */
Local_text_no conf_min; /* Lowest used local_text_no in conf */
Bool ready;
#ifndef NDEFENSIVE_CHECKS
Local_text_no prev;
#endif
i = 0; /* Number of texts in read_texts in Membership which are
included in last_text_read. */
/* (conf_min <= x <= conf_max) if x is an existing local_text_no */
conf_max = conf->texts.first_local_no + conf->texts.no_of_texts - 1;
conf_min = conf->texts.first_local_no;
do
{
ready = TRUE;
/* Flag all removed texts as read, if that is not already done. */
if (m->last_text_read < conf_min - 1)
m->last_text_read = conf_min - 1;
/* Increase m->last_text_read if
* * the user has read the text (last_text_read+1)
* * text (last_text_read+1) is deleted.
*/
/* Skip any texts in read_texts which are already handled. */
for (handled = 0; handled < m->no_of_read
&& m->read_texts[handled] < m->last_text_read + 1; )
{
handled++;
}
if ( m->last_text_read < conf_max) /* Does (last_text_read+1) exist? */
/* This loops advances m->last_text_read as far as possible,
advancing handled along when appropriate. m->last_text_read
can be increased for one of two reasons:
· The text is present in read_texts.
· The text is deleted.
This loop handles both cases. */
for ( ; ; )
{
if (handled < m->no_of_read
&& m->read_texts[handled] == m->last_text_read + 1)
{
if ( m->no_of_read > i /* Read? */
&& m->read_texts[ i ] == m->last_text_read + 1 )
{
i++;
m->last_text_read++;
ready = FALSE;
}
else
{
/* Is the text deleted? */
if ( m->last_text_read + 1 < conf_min /* Deleted and older
than any text that
exists in the
conference. */
|| (conf->texts.texts /* Deleted? */
[ m->last_text_read + 1 - conf_min ]
== 0 ) )
{
m->last_text_read++;
ready = FALSE;
}
}
/* This text is present in read_texts. */
m->last_text_read++;
handled++;
}
} while ( ready == FALSE );
/* Delete the first i entries in read_texts */
if ( i > 0 )
else if (conf->texts.texts[m->last_text_read + 1 - conf_min] == 0)
{
/* This text is deleted. */
m->last_text_read++;
}
else
break;
}
/* Delete all handled entries in read_texts. */
if (handled > 0)
{
m->no_of_read -= i;
m->no_of_read -= handled;
for (locp = m->read_texts;
locp < m->read_texts + m->no_of_read;
locp++)
{
*locp = *(locp + i);
*locp = *(locp + handled);
}
}
......@@ -379,7 +377,8 @@ adjust_read( Membership * m,
log("Bug in adjust_read. Conference %lu, Priority %lu\n"
"\tprev = %lu, i = %lu, m->read_texts[i] = %lu\n",
(unsigned long)m->conf_no, (unsigned long)m->priority,
(unsigned long)prev, (unsigned long)i, (unsigned long)m->read_texts[i]);
(unsigned long)prev, (unsigned long)i,
(unsigned long)m->read_texts[i]);
}
prev = m->read_texts[ i ];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment