]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/new_pair.c
ncurses 6.2 - patch 20200829
[ncurses.git] / ncurses / base / new_pair.c
index c47e61e7e8d7eeca4acadd9d7b2c78cecc4986f1..92131232e8695edf52b51f8902fac008176ef61c 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2017,2018 Free Software Foundation, Inc.                   *
+ * Copyright 2018-2019,2020 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            *
  *                                                                          *
  * 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
 
 
 #endif
 
-MODULE_ID("$Id: new_pair.c,v 1.17 2018/12/29 21:27:21 tom Exp $")
+MODULE_ID("$Id: new_pair.c,v 1.20 2020/04/11 16:06:56 tom Exp $")
 
 #if NCURSES_EXT_COLORS
 
 
 #if NCURSES_EXT_COLORS
 
@@ -102,13 +103,17 @@ dumpit(SCREEN *sp, int pair, const char *tag)
     char bigbuf[256 * 20];
     char *p = bigbuf;
     int n;
     char bigbuf[256 * 20];
     char *p = bigbuf;
     int n;
-    sprintf(p, "%s", tag);
-    p += strlen(p);
+    size_t have = sizeof(bigbuf);
+
+    _nc_STRCPY(p, tag, have);
     for (n = 0; n < sp->_pair_limit; ++n) {
        if (list[n].mode != cpFREE) {
     for (n = 0; n < sp->_pair_limit; ++n) {
        if (list[n].mode != cpFREE) {
-           sprintf(p, " %d%c(%d,%d)",
-                   n, n == pair ? '@' : ':', list[n].next, list[n].prev);
            p += strlen(p);
            p += strlen(p);
+           if ((size_t) (p - bigbuf) + 50 > have)
+               break;
+           _nc_SPRINTF(p, _nc_SLIMIT(have - (p - bigbuf))
+                       " %d%c(%d,%d)",
+                       n, n == pair ? '@' : ':', list[n].next, list[n].prev);
        }
     }
     T(("(%d/%d) %ld - %s",
        }
     }
     T(("(%d/%d) %ld - %s",
@@ -139,17 +144,16 @@ static int
 _nc_find_color_pair(SCREEN *sp, int fg, int bg)
 {
     colorpair_t find;
 _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;
     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;
 }
     }
     return result;
 }
@@ -192,7 +196,10 @@ NCURSES_EXPORT(void)
 _nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next)
 {
     colorpair_t *last;
 _nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next)
 {
     colorpair_t *last;
+
     if (ValidPair(sp, pair)) {
     if (ValidPair(sp, pair)) {
+       bool used;
+
        ReservePairs(sp, pair);
        last = &(sp->_color_pairs[pair]);
        delink_color_pair(sp, pair);
        ReservePairs(sp, pair);
        last = &(sp->_color_pairs[pair]);
        delink_color_pair(sp, pair);
@@ -200,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);
            (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);
            /* create a new entry in fast index */
            *last = *next;
            tsearch(last, &sp->_ordered_pairs, compare_data);