X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Fnew_pair.c;h=c04f4acbb95d7166f875a76c242fb0834b70da21;hp=2c3c2fb82a2d4c01420b5c8ba47372589a50d202;hb=fae162795e065e5901068152e91f2962b6b247f3;hpb=eccca377f55c70b12e3e92621d94d1e1c1fcfb7d diff --git a/ncurses/base/new_pair.c b/ncurses/base/new_pair.c index 2c3c2fb8..c04f4acb 100644 --- a/ncurses/base/new_pair.c +++ b/ncurses/base/new_pair.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 2017-2018,2019 Free Software Foundation, Inc. * + * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -60,7 +61,7 @@ #endif -MODULE_ID("$Id: new_pair.c,v 1.18 2019/01/21 14:54:47 tom Exp $") +MODULE_ID("$Id: new_pair.c,v 1.21 2021/02/14 00:17:09 tom Exp $") #if NCURSES_EXT_COLORS @@ -143,17 +144,16 @@ static int _nc_find_color_pair(SCREEN *sp, int fg, int bg) { colorpair_t find; - int result; - void *pp; + int result = -1; 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) { + void *pp; + if ((pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) { + colorpair_t *temp = *(colorpair_t **) pp; + result = (int) (temp - sp->_color_pairs); + } } return result; } @@ -196,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); @@ -204,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);