]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_color.c
ncurses 6.1 - patch 20180303
[ncurses.git] / ncurses / base / lib_color.c
index 09787afdbd84685a7043156a311571c0b813e7ff..41496eed612994b62c85a2d766ed4741b9f46af3 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2017,2018 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            *
@@ -48,7 +48,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_color.c,v 1.132 2017/08/12 22:23:52 tom Exp $")
+MODULE_ID("$Id: lib_color.c,v 1.137 2018/03/01 15:02:12 tom Exp $")
 
 #ifdef USE_TERM_DRIVER
 #define CanChange      InfoOf(SP_PARM).canchange
@@ -266,7 +266,7 @@ init_direct_colors(NCURSES_SP_DCL0)
        }
 
        if ((n = tigetflag(name)) > 0) {
-           n = width / 3;
+           n = (width + 2) / 3;
            result->bits.red = UChar(n);
            result->bits.green = UChar(n);
            result->bits.blue = UChar(width - (2 * n));
@@ -282,6 +282,7 @@ init_direct_colors(NCURSES_SP_DCL0)
            switch (sscanf(s, "%d/%d/%d", &red, &green, &blue)) {
            default:
                blue = width - (2 * n);
+               /* FALLTHRU */
            case 1:
                green = n;
                /* FALLTHRU */
@@ -533,7 +534,7 @@ _nc_reserve_pairs(SCREEN *sp, int want)
        if (sp->_color_pairs == 0) {
            sp->_color_pairs = TYPE_CALLOC(colorpair_t, have);
        } else if (have > sp->_pair_alloc) {
-#if USE_NEW_PAIR
+#if NCURSES_EXT_COLORS
            colorpair_t *next;
 
            if ((next = typeCalloc(colorpair_t, have)) == 0)
@@ -546,7 +547,7 @@ _nc_reserve_pairs(SCREEN *sp, int want)
            TYPE_REALLOC(colorpair_t, have, sp->_color_pairs);
            if (sp->_color_pairs != 0) {
                memset(sp->_color_pairs + sp->_pair_alloc, 0,
-                      sizeof(colorpair_t) * (have - sp->_pair_alloc));
+                      sizeof(colorpair_t) * (size_t) (have - sp->_pair_alloc));
            }
 #endif
        }
@@ -1081,7 +1082,7 @@ _nc_do_color(int old_pair, int pair, int reverse, NCURSES_OUTC outc)
 }
 #endif
 
-#if USE_EXTENDED_COLORS
+#if NCURSES_EXT_COLORS
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(init_extended_pair) (NCURSES_SP_DCLx int pair, int f, int b)
 {
@@ -1117,8 +1118,11 @@ NCURSES_SP_NAME(reset_color_pairs) (NCURSES_SP_DCL0)
 {
     if (SP_PARM != 0) {
        if (SP_PARM->_color_pairs) {
-           memset(sp->_color_pairs, 0, sizeof(colorpair_t) * (size_t) sp->_pair_alloc);
            _nc_free_ordered_pairs(SP_PARM);
+           free(SP_PARM->_color_pairs);
+           SP_PARM->_color_pairs = 0;
+           SP_PARM->_pair_alloc = 0;
+           _nc_reserve_pairs(SP_PARM, 16);
            clearok(CurScreen(SP_PARM), TRUE);
            touchwin(StdScreen(SP_PARM));
        }
@@ -1160,4 +1164,4 @@ reset_color_pairs(void)
     NCURSES_SP_NAME(reset_color_pairs) (CURRENT_SCREEN);
 }
 #endif /* NCURSES_SP_FUNCS */
-#endif /* USE_EXTENDED_COLORS */
+#endif /* NCURSES_EXT_COLORS */