From 564af5129c2e3de82d7d9ed80dcbbd55d482b435 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 10 Jan 2021 10:25:06 -0800 Subject: Fix check for empty colors left. Because pair "0" is reserved (and we start searching at index 1), we only have access to (COLOR_PAIRS - 1) pairs. Also, don't increment UserColors during the check, because that would incorrectly inflate the number of color pairs allocated if none are available. That would delay or even remove the ability to reallocate pairs after future color pair frees. It actually would make more sense to just check (index > COLOR_PAIRS - 1). But since UserColors is incremented here, and is used in dprint statements, keep the check consistent. --- color.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/color.c b/color.c index 8558660c..c97275d9 100644 --- a/color.c +++ b/color.c @@ -342,8 +342,12 @@ static int _mutt_alloc_color (int fg, int bg, int type) p = p->next; } - /* check to see if there are colors left */ - if (++UserColors > COLOR_PAIRS) return (A_NORMAL); + /* check to see if there are colors left. + * note: pair 0 is reserved for "default" so we actually only have access + * to COLOR_PAIRS-1 pairs. */ + if (UserColors >= (COLOR_PAIRS - 1)) + return (A_NORMAL); + UserColors++; p = (COLOR_LIST *) safe_calloc (1, sizeof (COLOR_LIST)); p->next = *last; -- cgit v1.2.3