diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-09-26 15:46:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 15:46:04 (GMT) |
commit | 00c352404a2f57f16a0b0d02eef5bdf1a1bd169f (patch) | |
tree | 316654758720062bba56bef086bb13dc100dfa22 | |
parent | 8bdaf9bf8e39b2ea374ee01a36b3c1bdaed01b23 (diff) | |
download | cpython-00c352404a2f57f16a0b0d02eef5bdf1a1bd169f.zip cpython-00c352404a2f57f16a0b0d02eef5bdf1a1bd169f.tar.gz cpython-00c352404a2f57f16a0b0d02eef5bdf1a1bd169f.tar.bz2 |
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 41351662bcd21672d8ccfa62fe44d72027e6bcf8)
Co-authored-by: Victor Stinner <vstinner@python.org>
-rw-r--r-- | Lib/test/test_cmd_line.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst | 3 | ||||
-rw-r--r-- | Python/initconfig.c | 3 |
3 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 84bd883..14de3d4 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -831,6 +831,8 @@ class CmdLineTest(unittest.TestCase): assert_python_failure('-X', 'int_max_str_digits', '-c', code) assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code) assert_python_failure('-X', 'int_max_str_digits=100', '-c', code) + assert_python_failure('-X', 'int_max_str_digits', '-c', code, + PYTHONINTMAXSTRDIGITS='4000') assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo') assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100') diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst new file mode 100644 index 0000000..a9b04ce --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-21-14-38-31.gh-issue-96848.WuoLzU.rst @@ -0,0 +1,3 @@ +Fix command line parsing: reject :option:`-X int_max_str_digits <-X>` option +with no value (invalid) when the :envvar:`PYTHONINTMAXSTRDIGITS` environment +variable is set to a valid limit. Patch by Victor Stinner. diff --git a/Python/initconfig.c b/Python/initconfig.c index 0d2077a..1e10e66 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -1774,10 +1774,10 @@ static PyStatus config_init_int_max_str_digits(PyConfig *config) { int maxdigits; - int valid = 0; const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS"); if (env) { + int valid = 0; if (!_Py_str_to_int(env, &maxdigits)) { valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD)); } @@ -1795,6 +1795,7 @@ config_init_int_max_str_digits(PyConfig *config) const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits"); if (xoption) { const wchar_t *sep = wcschr(xoption, L'='); + int valid = 0; if (sep) { if (!config_wstr_to_int(sep + 1, &maxdigits)) { valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD)); |