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: Jeffrey Kintscher
Subject: Re: bug in start_color() affecting extended_pair_content() in version 6.1
Date: Mon, 20 May 2019 14:34:37 -0700
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

Sorry for leaving the system details out.

VERSION file:
5:0:9    6.0    20180127

downloaded May 18 from:
ftp://ftp.invisible-island.net/ncurses/ncurses.tar.gz

configure command line (run in "build" subdirectory):
../configure --prefix=${HOME}/src/ncurses-6.1/inst --enable-ext-colors --with-debug --enable-ext-funcs  --with-shared --enable-widec

make command line:
make -j 7

uname -a:
Darwin jfoo.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

OS:
macOS Mojave 10.14.4

gcc --version:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

test program compile line:
clang -pipe -o bbpo-36630 bbpo-36630.c -lncursesw_g -g -O0 -I${HOME}/src/ncurses-6.1/inst/include/ncursesw -I${HOME}/src/ncurses-6.1/inst/include -L${HOME}/src/ncurses-6.1/inst/

//Jeff

On 5/20/19 1:09 AM, Thomas Dickey wrote:
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.


-- 
-----------------------------------------
>From there to here, from here to there,
funny things are everywhere.
           -- Theodore Geisel

reply via email to

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