Skip to content

Commit 18a0cdb

Browse files
[3.8] gh-96848: Fix -X int_max_str_digits option parsing (GH-96988) (GH-97575)
Fix command line parsing: reject "-X int_max_str_digits" option with no value (invalid) when the PYTHONINTMAXSTRDIGITS environment variable is set to a valid limit. (cherry picked from commit 4135166) Co-authored-by: Victor Stinner <[email protected]>
1 parent 12c72d6 commit 18a0cdb

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Lib/test/test_cmd_line.py

+2
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ def test_int_max_str_digits(self):
794794
assert_python_failure('-X', 'int_max_str_digits', '-c', code)
795795
assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code)
796796
assert_python_failure('-X', 'int_max_str_digits=100', '-c', code)
797+
assert_python_failure('-X', 'int_max_str_digits', '-c', code,
798+
PYTHONINTMAXSTRDIGITS='4000')
797799

798800
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo')
799801
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix command line parsing: reject :option:`-X int_max_str_digits <-X>` option
2+
with no value (invalid) when the :envvar:`PYTHONINTMAXSTRDIGITS` environment
3+
variable is set to a valid limit. Patch by Victor Stinner.

Python/initconfig.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,10 @@ static PyStatus
14031403
config_init_int_max_str_digits(PyConfig *config)
14041404
{
14051405
int maxdigits;
1406-
int valid = 0;
14071406

14081407
const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
14091408
if (env) {
1409+
int valid = 0;
14101410
if (!_Py_str_to_int(env, &maxdigits)) {
14111411
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
14121412
}
@@ -1424,6 +1424,7 @@ config_init_int_max_str_digits(PyConfig *config)
14241424
const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
14251425
if (xoption) {
14261426
const wchar_t *sep = wcschr(xoption, L'=');
1427+
int valid = 0;
14271428
if (sep) {
14281429
if (!config_wstr_to_int(sep + 1, &maxdigits)) {
14291430
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));

0 commit comments

Comments
 (0)