8000 gh-96848: Fix -X int_max_str_digits option parsing (#96988) · python/cpython@4135166 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4135166

Browse files
authored
gh-96848: Fix -X int_max_str_digits option parsing (#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.
1 parent 2b428a1 commit 4135166

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Lib/test/test_cmd_line.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ def test_int_max_str_digits(self):
871871
assert_python_failure('-X', 'int_max_str_digits', '-c', code)
872872
assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code)
873873
assert_python_failure('-X', 'int_max_str_digits=100', '-c', code)
874+
assert_python_failure('-X', 'int_max_str_digits', '-c', code,
875+
PYTHONINTMAXSTRDIGITS='4000')
874876

875877
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo')
876878
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100')
Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,10 +1779,10 @@ static PyStatus
17791779
config_init_int_max_str_digits(PyConfig *config)
17801780
{
17811781
int maxdigits;
1782-
int valid = 0;
17831782

17841783
const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
17851784
if (env) {
1785+
int valid = 0;
17861786
if (!_Py_str_to_int(env, &maxdigits)) {
17871787
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
17881788
}
@@ -1800,6 +1800,7 @@ config_init_int_max_str_digits(PyConfig *config)
18001800
const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
18011801
if (xoption) {
18021802
const wchar_t *sep = wcschr(xoption, L'=');
1803+
int valid = 0;
18031804
if (sep) {
18041805
if (!config_wstr_to_int(sep + 1, &maxdigits)) {
18051806
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));

0 commit comments

Comments
 (0)
0