diff options
author | Kevin McCarthy <kevin@8t8.us> | 2021-01-10 10:25:06 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2021-01-10 13:03:36 -0800 |
commit | 564af5129c2e3de82d7d9ed80dcbbd55d482b435 (patch) | |
tree | a1f8c58eef4b0ed23917d80d4fafd3001ce688eb | |
parent | 1ffe93ef37a6b65aba67ba2b888702b2f67aef56 (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.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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; |