X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Fnew_pair.c;h=92131232e8695edf52b51f8902fac008176ef61c;hp=547ab28180668bed49f2562ef8f91640680d3886;hb=1f7a36fe16b11bb4aab51be89bbc1b0f75936b78;hpb=47d2fb4537d9ad5bb14f4810561a327930ca4280 diff --git a/ncurses/base/new_pair.c b/ncurses/base/new_pair.c index 547ab281..92131232 100644 --- a/ncurses/base/new_pair.c +++ b/ncurses/base/new_pair.c @@ -61,7 +61,7 @@ #endif -MODULE_ID("$Id: new_pair.c,v 1.19 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: new_pair.c,v 1.20 2020/04/11 16:06:56 tom Exp $") #if NCURSES_EXT_COLORS @@ -144,17 +144,16 @@ static int _nc_find_color_pair(SCREEN *sp, int fg, int bg) { colorpair_t find; - int result; + int result = -1; void *pp; find.fg = fg; find.bg = bg; - if (sp != 0 && - (pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) { - colorpair_t *temp = *(colorpair_t **) pp; - result = (int) (temp - sp->_color_pairs); - } else { - result = -1; + if (sp != 0) { + if ((pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) { + colorpair_t *temp = *(colorpair_t **) pp; + result = (int) (temp - sp->_color_pairs); + } } return result; } @@ -197,7 +196,10 @@ NCURSES_EXPORT(void) _nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next) { colorpair_t *last; + if (ValidPair(sp, pair)) { + bool used; + ReservePairs(sp, pair); last = &(sp->_color_pairs[pair]); delink_color_pair(sp, pair); @@ -205,6 +207,11 @@ _nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next) (last->fg != next->fg || last->bg != next->bg)) { /* remove the old entry from fast index */ tdelete(last, &sp->_ordered_pairs, compare_data); + used = FALSE; + } else { + used = (last->mode != cpFREE); + } + if (!used) { /* create a new entry in fast index */ *last = *next; tsearch(last, &sp->_ordered_pairs, compare_data);