Skip to content

Commit 00c3524

Browse files
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 8bdaf9b commit 00c3524

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
@@ -831,6 +831,8 @@ def test_int_max_str_digits(self):
831831
assert_python_failure('-X', 'int_max_str_digits', '-c', code)
832832
assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code)
833833
assert_python_failure('-X', 'int_max_str_digits=100', '-c', code)
834+
assert_python_failure('-X', 'int_max_str_digits', '-c', code,
835+
PYTHONINTMAXSTRDIGITS='4000')
834836

835837
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo')
836838
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
@@ -1774,10 +1774,10 @@ static PyStatus
17741774
config_init_int_max_str_digits(PyConfig *config)
17751775
{
17761776
int maxdigits;
1777-
int valid = 0;
17781777

17791778
const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
17801779
if (env) {
1780+
int valid = 0;
17811781
if (!_Py_str_to_int(env, &maxdigits)) {
17821782
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
17831783
}
@@ -1795,6 +1795,7 @@ config_init_int_max_str_digits(PyConfig *config)
17951795
const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
17961796
if (xoption) {
17971797
const wchar_t *sep = wcschr(xoption, L'=');
1798+
int valid = 0;
17981799
if (sep) {
17991800
if (!config_wstr_to_int(sep + 1, &maxdigits)) {
18001801
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));

0 commit comments

Comments
 (0)