summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-01-03 20:51:11 (GMT)
committerGitHub <noreply@github.com>2021-01-03 20:51:11 (GMT)
commit1470edd6131c29b8a09ce012cdfee3afa269d553 (patch)
treebd719cd5b488dc5c17716374826bd774e11884d0 /Modules/clinic
parent7c83eaa536d2f436ae46211ca48692f576c732f0 (diff)
downloadcpython-1470edd6131c29b8a09ce012cdfee3afa269d553.zip
cpython-1470edd6131c29b8a09ce012cdfee3afa269d553.tar.gz
cpython-1470edd6131c29b8a09ce012cdfee3afa269d553.tar.bz2
bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874)
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/_cursesmodule.c.h33
1 files changed, 17 insertions, 16 deletions
diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h
index 34e09e4..e46a8e3 100644
--- a/Modules/clinic/_cursesmodule.c.h
+++ b/Modules/clinic/_cursesmodule.c.h
@@ -1958,7 +1958,7 @@ PyDoc_STRVAR(_curses_color_content__doc__,
"Return the red, green, and blue (RGB) components of the specified color.\n"
"\n"
" color_number\n"
-" The number of the color (0 - COLORS).\n"
+" The number of the color (0 - (COLORS-1)).\n"
"\n"
"A 3-tuple is returned, containing the R, G, B values for the given color,\n"
"which will be between 0 (no component) and 1000 (maximum amount of component).");
@@ -1985,13 +1985,13 @@ exit:
}
PyDoc_STRVAR(_curses_color_pair__doc__,
-"color_pair($module, color_number, /)\n"
+"color_pair($module, pair_number, /)\n"
"--\n"
"\n"
"Return the attribute value for displaying text in the specified color.\n"
"\n"
-" color_number\n"
-" The number of the color (0 - COLORS).\n"
+" pair_number\n"
+" The number of the color pair.\n"
"\n"
"This attribute value can be combined with A_STANDOUT, A_REVERSE, and the\n"
"other A_* attributes. pair_number() is the counterpart to this function.");
@@ -2000,18 +2000,19 @@ PyDoc_STRVAR(_curses_color_pair__doc__,
{"color_pair", (PyCFunction)_curses_color_pair, METH_O, _curses_color_pair__doc__},
static PyObject *
-_curses_color_pair_impl(PyObject *module, int color_number);
+_curses_color_pair_impl(PyObject *module, int pair_number);
static PyObject *
_curses_color_pair(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
- int color_number;
+ int pair_number;
- if (!color_converter(arg, &color_number)) {
+ pair_number = _PyLong_AsInt(arg);
+ if (pair_number == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_color_pair_impl(module, color_number);
+ return_value = _curses_color_pair_impl(module, pair_number);
exit:
return return_value;
@@ -2542,7 +2543,7 @@ PyDoc_STRVAR(_curses_init_color__doc__,
"Change the definition of a color.\n"
"\n"
" color_number\n"
-" The number of the color to be changed (0 - COLORS).\n"
+" The number of the color to be changed (0 - (COLORS-1)).\n"
" r\n"
" Red component (0 - 1000).\n"
" g\n"
@@ -2552,7 +2553,7 @@ PyDoc_STRVAR(_curses_init_color__doc__,
"\n"
"When init_color() is used, all occurrences of that color on the screen\n"
"immediately change to the new definition. This function is a no-op on\n"
-"most terminals; it is active only if can_change_color() returns 1.");
+"most terminals; it is active only if can_change_color() returns true.");
#define _CURSES_INIT_COLOR_METHODDEF \
{"init_color", (PyCFunction)(void(*)(void))_curses_init_color, METH_FASTCALL, _curses_init_color__doc__},
@@ -2600,9 +2601,9 @@ PyDoc_STRVAR(_curses_init_pair__doc__,
" pair_number\n"
" The number of the color-pair to be changed (1 - (COLOR_PAIRS-1)).\n"
" fg\n"
-" Foreground color number (0 - COLORS).\n"
+" Foreground color number (-1 - (COLORS-1)).\n"
" bg\n"
-" Background color number (0 - COLORS).\n"
+" Background color number (-1 - (COLORS-1)).\n"
"\n"
"If the color-pair was previously initialized, the screen is refreshed and\n"
"all occurrences of that color-pair are changed to the new definition.");
@@ -2627,10 +2628,10 @@ _curses_init_pair(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (!pair_converter(args[0], &pair_number)) {
goto exit;
}
- if (!color_converter(args[1], &fg)) {
+ if (!color_allow_default_converter(args[1], &fg)) {
goto exit;
}
- if (!color_converter(args[2], &bg)) {
+ if (!color_allow_default_converter(args[2], &bg)) {
goto exit;
}
return_value = _curses_init_pair_impl(module, pair_number, fg, bg);
@@ -3403,7 +3404,7 @@ PyDoc_STRVAR(_curses_pair_content__doc__,
"Return a tuple (fg, bg) containing the colors for the requested color pair.\n"
"\n"
" pair_number\n"
-" The number of the color pair (1 - (COLOR_PAIRS-1)).");
+" The number of the color pair (0 - (COLOR_PAIRS-1)).");
#define _CURSES_PAIR_CONTENT_METHODDEF \
{"pair_content", (PyCFunction)_curses_pair_content, METH_O, _curses_pair_content__doc__},
@@ -4288,4 +4289,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored
#ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF
#define _CURSES_USE_DEFAULT_COLORS_METHODDEF
#endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */
-/*[clinic end generated code: output=92bad2172fef9747 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ae6559aa61200289 input=a9049054013a1b77]*/