Skip to content

Commit 67f5d24

Browse files
miss-islingtonvstinner
authored andcommitted
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 <vstinner@python.org>
1 parent 9e008fe commit 67f5d24

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
@@ -874,6 +874,8 @@ def test_int_max_str_digits(self):
874874
assert_python_failure('-X', 'int_max_str_digits', '-c', code)
875875
assert_python_failure('-X', 'int_max_str_digits=foo', '-c', code)
876876
assert_python_failure('-X', 'int_max_str_digits=100', '-c', code)
877+
assert_python_failure('-X', 'int_max_str_digits', '-c', code,
878+
PYTHONINTMAXSTRDIGITS='4000')
877879

878880
assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='foo')
879881
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
@@ -1734,10 +1734,10 @@ static PyStatus
17341734
config_init_int_max_str_digits(PyConfig *config)
17351735
{
17361736
int maxdigits;
1737-
int valid = 0;
17381737

17391738
const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
17401739
if (env) {
1740+
int valid = 0;
17411741
if (!_Py_str_to_int(env, &maxdigits)) {
17421742
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
17431743
}
@@ -1755,6 +1755,7 @@ config_init_int_max_str_digits(PyConfig *config)
17551755
const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
17561756
if (xoption) {
17571757
const wchar_t *sep = wcschr(xoption, L'=');
1758+
int valid = 0;
17581759
if (sep) {
17591760
if (!config_wstr_to_int(sep + 1, &maxdigits)) {
17601761
valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy