mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									2b428a1fae
								
							
						
					
					
						commit
						41351662bc
					
				
					 3 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
					@ -871,6 +871,8 @@ def test_int_max_str_digits(self):
 | 
				
			||||||
        assert_python_failure('-X', 'int_max_str_digits', '-c', code)
 | 
					        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=foo', '-c', code)
 | 
				
			||||||
        assert_python_failure('-X', 'int_max_str_digits=100', '-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='foo')
 | 
				
			||||||
        assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100')
 | 
					        assert_python_failure('-c', code, PYTHONINTMAXSTRDIGITS='100')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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.
 | 
				
			||||||
| 
						 | 
					@ -1779,10 +1779,10 @@ static PyStatus
 | 
				
			||||||
config_init_int_max_str_digits(PyConfig *config)
 | 
					config_init_int_max_str_digits(PyConfig *config)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int maxdigits;
 | 
					    int maxdigits;
 | 
				
			||||||
    int valid = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
 | 
					    const char *env = config_get_env(config, "PYTHONINTMAXSTRDIGITS");
 | 
				
			||||||
    if (env) {
 | 
					    if (env) {
 | 
				
			||||||
 | 
					        int valid = 0;
 | 
				
			||||||
        if (!_Py_str_to_int(env, &maxdigits)) {
 | 
					        if (!_Py_str_to_int(env, &maxdigits)) {
 | 
				
			||||||
            valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
 | 
					            valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1800,6 +1800,7 @@ config_init_int_max_str_digits(PyConfig *config)
 | 
				
			||||||
    const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
 | 
					    const wchar_t *xoption = config_get_xoption(config, L"int_max_str_digits");
 | 
				
			||||||
    if (xoption) {
 | 
					    if (xoption) {
 | 
				
			||||||
        const wchar_t *sep = wcschr(xoption, L'=');
 | 
					        const wchar_t *sep = wcschr(xoption, L'=');
 | 
				
			||||||
 | 
					        int valid = 0;
 | 
				
			||||||
        if (sep) {
 | 
					        if (sep) {
 | 
				
			||||||
            if (!config_wstr_to_int(sep + 1, &maxdigits)) {
 | 
					            if (!config_wstr_to_int(sep + 1, &maxdigits)) {
 | 
				
			||||||
                valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
 | 
					                valid = ((maxdigits == 0) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue