Skip to content

Commit 358b7a4

Browse files
[3.9] gh-96848: Fix -X int_max_str_digits option parsing (GH-96988) (GH-97574)
gh-96848: Fix -X int_max_str_digits option parsing (GH-96988) 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 938223e commit 358b7a4

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
@@ -821,6 +821,8 @@ def test_int_max_str_digits(self):
821821
assert_python_failure('-X', 'int_max_str_digits', '-c', code)
822822
assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code)
823823
assert_python_failure('-X', 'int_max_str_digits=100', '-c', code)
824+
assert_python_failure('-X', 'int_max_str_digits', '-c', code,
825+
PYTHONINTMAXSTRDIGITS='4000')
824826

825827
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo')
826828
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
@@ -1426,10 +1426,10 @@ static PyStatus
14261426
config_init_int_max_str_digits(PyConfig *config)
14271427
{
14281428
int maxdigits;
1429-
int valid = 0;
14301429

14311430
const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
14321431
if (env) {
1432+
int valid = 0;
14331433
if (!_Py_str_to_int(env, &maxdigits)) {
14341434
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
14351435
}
@@ -1447,6 +1447,7 @@ config_init_int_max_str_digits(PyConfig *config)
14471447
const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
14481448
if (xoption) {
14491449
const wchar_t *sep = wcschr(xoption, L'=');
1450+
int valid = 0;
14501451
if (sep) {
14511452
if (!config_wstr_to_int(sep + 1, &maxdigits)) {
14521453
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));

0 commit comments

Comments
 (0)