summaryrefslogtreecommitdiff
path: root/news_gui.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-12-05 23:37:04 +0000
committerDarkvater <Darkvater@openttd.org>2006-12-05 23:37:04 +0000
commitf2a70e3e26d2aeb75a63b60338bdd12f3046f5cd (patch)
tree4263fe6031c48fdc4b1ea0193275d0bff150ecf8 /news_gui.c
parent0e10e86137b6a736494d4ba02f93909ee0666080 (diff)
downloadopenttd-f2a70e3e26d2aeb75a63b60338bdd12f3046f5cd.tar.xz
(svn r7388) -Fix (r7384 / r7368 / r3757): When adding a new news item for the first time (_latest_news
is INVALID_NEWS), make it the value of _oldest_news, not zero as DeleteVehicleNews can change _oldest_news. Also remove the (i == INVALID_NEWS) return 0; guard from increaseIndex as it's only used in 2 places, nowhere else.
Diffstat (limited to 'news_gui.c')
-rw-r--r--news_gui.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/news_gui.c b/news_gui.c
index f6a10748c..05804d9c8 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -230,7 +230,7 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
* queue and deals with overflows when increasing the index */
static inline NewsID increaseIndex(NewsID i)
{
- if (i == INVALID_NEWS) return 0;
+ assert(i != INVALID_NEWS);
return (i + 1) % MAX_NEWS;
}
@@ -275,9 +275,11 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
_forced_news = INVALID_NEWS;
if (_total_news < MAX_NEWS) _total_news++;
- // make sure our pointer isn't overflowing
+ /* Increase _latest_news. If we have no news yet, use _oldest news as an
+ * index. We cannot use 0 as _oldest_news can jump around due to
+ * DeleteVehicleNews */
l_news = _latest_news;
- _latest_news = increaseIndex(_latest_news);
+ _latest_news = (_latest_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_latest_news);
/* If the fifo-buffer is full, overwrite the oldest entry */
if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
@@ -489,7 +491,7 @@ static void MoveToNextItem(void)
if (_current_news != _latest_news) {
NewsItem *ni;
- _current_news = increaseIndex(_current_news);
+ _current_news = (_current_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_current_news);
ni = &_news_items[_current_news];
// check the date, don't show too old items