From 070e3b4178ebcc23be88e37beac11a902fd085ce Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 20 Nov 2009 06:33:26 +0000 Subject: [PATCH] Remove oldest messages from log when limit is hit, not newest. --- status.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/status.c b/status.c index 31e25215..bff7afe9 100644 --- a/status.c +++ b/status.c @@ -650,10 +650,13 @@ status_message_set(struct client *c, const char *fmt, ...) limit = 0; else limit = options_get_number(&s->options, "message-limit"); - for (i = ARRAY_LENGTH(&c->message_log); i > limit; i--) { - msg = &ARRAY_ITEM(&c->message_log, i - 1); - xfree(msg->msg); - ARRAY_REMOVE(&c->message_log, i - 1); + if (ARRAY_LENGTH(&c->message_log) > limit) { + limit = ARRAY_LENGTH(&c->message_log) - limit; + for (i = 0; i < limit; i++) { + msg = &ARRAY_FIRST(&c->message_log); + xfree(msg->msg); + ARRAY_REMOVE(&c->message_log, 0); + } } delay = options_get_number(&c->session->options, "display-time");