bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in start_color() affecting extended_pair_content() in version 6.


From: Thomas Dickey
Subject: Re: bug in start_color() affecting extended_pair_content() in version 6.1
Date: Mon, 20 May 2019 04:09:21 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Sun, May 19, 2019 at 06:48:49PM -0700, Jeffrey Kintscher wrote:
> I was working on adding the new extended color functions to Python when I
> encountered a problem with extended_pair_content(COLOR_PAIRS-1, &f, &b)
> returning -1 when using the terminal "xterm-256color". Here is example code
> highlighting the problem:

there's no version/patch information here, nor the system (which would let
me guess how ncurses is built).
 
> #include <ncurses.h>
> #include <stdio.h>
> 
> int main(int argc, char **argv, char **env)
> {
>     int b, f;
> 
>     initscr();
>     start_color();
>     printf("init_extended_pair(COLOR_PAIRS-1, 1, 1): %d\n",
> init_extended_pair(COLOR_PAIRS-1, 1, 1));
>     printf("COLOR_PAIRS: %d\n", COLOR_PAIRS);
>     printf("extended_pair_content(COLOR_PAIRS-1, &f, &b): %d\n",
> extended_pair_content(COLOR_PAIRS-1, &f, &b));
>     printf("f: %d\nb: %d\n", f, b);
>     return 0;
> }
> 
> 
> extended_pair_content() eventually calls _nc_pair_content() which invokes
> the macro ValidPair(sp, pair). ValidPair() evaluates to false because the
> check (pair < sp->_pair_limit) fails. According to the debugger, pair ==
> 65535 and sp->_pair_limit == 32767.

If sp->pair_limit is 32767, that's likely an ABI 5 configuration.
 
> sp->_pair_limit gets set in start_color() (in ncurses/base/libcolor.c):
> 
>     if (maxpairs > 0 && maxcolors > 0) {
>         SP_PARM->_pair_limit = maxpairs;
> ...
>         SP_PARM->_pair_limit += (1 + (2 * maxcolors));
>         SP_PARM->_pair_limit = limit_PAIRS(SP_PARM->_pair_limit);
> 
> SP_PARM->_pair_limit is set to 65536, increased to 66049, then clamped at
> 32767. This is because the limit_PAIRS() macro clamps the value it is passed
> to within the limits for type NCURSES_PAIRS_T, which is defined as short. 

NCURSES_PAIRS_T is always short...

but the quoted code is in the ABI 5 part (see lib_color.c around line 400):

#if NCURSES_EXT_FUNCS
            /*
             * If using default colors, allocate extra space in table to
             * allow for default-color as a component of a color-pair.
             */
            SP_PARM->_pair_limit += (1 + (2 * maxcolors));
#if !NCURSES_EXT_COLORS
            SP_PARM->_pair_limit = limit_PAIRS(SP_PARM->_pair_limit);
#endif
#endif /* NCURSES_EXT_FUNCS */

> So, SP_PARM->_pair_limit gets set to 32767 which causes ValidPair(sp,
> COLOR_PAIRS-1) to fail.

You may find a bug in the extended colors, but almost all of the reports
will be for ABI 5 versus ABI 6.

-- 
Thomas E. Dickey <address@hidden>
https://invisible-island.net
ftp://ftp.invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]