Skip to content

Commit 98884f5

Browse files
authored
[3.7] gh-96848: Fix -X int_max_str_digits option parsing (#96988) (#97576)
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)
1 parent 46796ed commit 98884f5

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
@@ -717,6 +717,8 @@ def test_int_max_str_digits(self):
717717
assert_python_failure('-X', 'int_max_str_digits', '-c', code)
718718
assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code)
719719
assert_python_failure('-X', 'int_max_str_digits=100', '-c', code)
720+
assert_python_failure('-X', 'int_max_str_digits', '-c', code,
721+
PYTHONINTMAXSTRDIGITS='4000')
720722

721723
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo')
722724
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.

Modules/main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1813,10 +1813,10 @@ static _PyInitError
18131813
config_init_int_max_str_digits(_PyCoreConfig *config)
18141814
{
18151815
int maxdigits;
1816-
int valid = 0;
18171816

18181817
const char *env = config_get_env_var("PYTHONINTMAXSTRDIGITS");
18191818
if (env) {
1819+
int valid = 0;
18201820
if (!pymain_str_to_int(env, &maxdigits)) {
18211821
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
18221822
}
@@ -1834,6 +1834,7 @@ config_init_int_max_str_digits(_PyCoreConfig *config)
18341834
const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
18351835
if (xoption) {
18361836
const wchar_t *sep = wcschr(xoption, L'=');
1837+
int valid = 0;
18371838
if (sep) {
18381839
if (!pymain_wstr_to_int(sep + 1, &maxdigits)) {
18391840
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));

0 commit comments

Comments
 (0)