[Top][All Lists]

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

bug in start_color() affecting extended_pair_content() in version 6.1

From: Jeffrey Kintscher
Subject: bug in start_color() affecting extended_pair_content() in version 6.1
Date: Sun, 19 May 2019 18:48:49 -0700
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

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:

#include <ncurses.h>
#include <stdio.h>

int main(int argc, char **argv, char **env)
    int b, f;

    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.

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.  So, SP_PARM->_pair_limit gets set to 32767 which causes ValidPair(sp, COLOR_PAIRS-1) to fail.

>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]