From 18445aa55d89c290f1f5b7e49a39c508e876e855 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 25 May 2010 15:09:59 +0000 Subject: [PATCH] * Fixed the off-by-one error in bbs view that causes a blank page to appear at the end when the number of messages is divisible by 20. --- webcit/bbsview_renderer.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/webcit/bbsview_renderer.c b/webcit/bbsview_renderer.c index 19ee628d1..8a02e35bf 100644 --- a/webcit/bbsview_renderer.c +++ b/webcit/bbsview_renderer.c @@ -40,6 +40,7 @@ struct bbsview { long lastseen; /* The number of the last seen message in this room */ int alloc_msgs; /* Currently allocated size of array */ int requested_page; /* Which page number did the user request? */ + int num_pages; /* Total number of pages in this room */ }; @@ -173,6 +174,13 @@ int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat, qsort(BBS->msgs, (size_t)(BBS->num_msgs), sizeof(long), bbsview_sortfunc); } + if ((BBS->num_msgs % Stat->maxmsgs) == 0) { + BBS->num_pages = BBS->num_msgs / Stat->maxmsgs; + } + else { + BBS->num_pages = (BBS->num_msgs / Stat->maxmsgs) + 1; + } + /* If the requested page number is "whichever page on which new messages start" * then change that to an actual page number now. */ @@ -200,10 +208,14 @@ int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat, BBS->requested_page = 0; } else { - BBS->requested_page = (BBS->num_msgs / Stat->maxmsgs); + BBS->requested_page = BBS->num_pages - 1; } } + /* keep the requested page within bounds */ + if (BBS->requested_page < 0) BBS->requested_page = 0; + if (BBS->requested_page >= BBS->num_pages) BBS->requested_page = BBS->num_pages - 1; + start_index = BBS->requested_page * Stat->maxmsgs; if (start_index < 0) start_index = 0; end_index = start_index + Stat->maxmsgs - 1; @@ -243,7 +255,7 @@ int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat, wc_printf(_("Go to page: ")); int first = 0; - int last = ( (Stat->maxmsgs > 0) ? (BBS->num_msgs / Stat->maxmsgs) : 0 ); + int last = BBS->num_pages - 1; for (i=0; i<=last; ++i) { -- 2.39.2