summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2021-01-10 10:25:06 -0800
committerKevin McCarthy <kevin@8t8.us>2021-01-10 13:03:36 -0800
commit564af5129c2e3de82d7d9ed80dcbbd55d482b435 (patch)
treea1f8c58eef4b0ed23917d80d4fafd3001ce688eb
parent1ffe93ef37a6b65aba67ba2b888702b2f67aef56 (diff)
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.
-rw-r--r--color.c8
1 files 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;