564af5129c2e3de82d7d9ed80dcbbd55d482b435 — Kevin McCarthy a month ago 1ffe93e
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.
1 files changed, 6 insertions(+), 2 deletions(-)

M color.c
M color.c => color.c +6 -2
@@ 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);

  p = (COLOR_LIST *) safe_calloc (1, sizeof (COLOR_LIST));
  p->next = *last;