[Python-checkins] CVS: python/dist/src/Python getargs.c,2.63,2.64

Jeremy Hylton jhylton@users.sourceforge.net
Sun, 09 Sep 2001 18:54:46 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv21097

Modified Files:
	getargs.c 
Log Message:
Fix core dump in PyArg_ParseTuple() with Unicode arguments.

Reported by Fredrik Lundh on python-dev.

The conversimple() code that handles Unicode arguments and converts
them to the default encoding now calls converterr() with the original
Unicode argument instead of the NULL returned by the failed encoding
attempt.


Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.63
retrieving revision 2.64
diff -C2 -d -r2.63 -r2.64
*** getargs.c	2001/08/28 16:37:51	2.63
--- getargs.c	2001/09/10 01:54:43	2.64
***************
*** 368,372 ****
  converterr(char *expected, PyObject *arg, char *msgbuf)
  {
! 	assert (expected != NULL);
  	sprintf(msgbuf, "must be %.50s, not %.50s", expected,
  		arg == Py_None ? "None" : arg->ob_type->tp_name);
--- 368,373 ----
  converterr(char *expected, PyObject *arg, char *msgbuf)
  {
! 	assert(expected != NULL);
! 	assert(arg != NULL); 
  	sprintf(msgbuf, "must be %.50s, not %.50s", expected,
  		arg == Py_None ? "None" : arg->ob_type->tp_name);
***************
*** 388,391 ****
--- 389,393 ----
  	char *format = *p_format;
  	char c = *format++;
+ 	PyObject *uarg;
  	
  	switch (c) {
***************
*** 569,578 ****
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				arg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (arg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(arg);
! 				*q = PyString_GET_SIZE(arg);
  			}
  #endif
--- 571,580 ----
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				uarg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (uarg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(uarg);
! 				*q = PyString_GET_SIZE(uarg);
  			}
  #endif
***************
*** 592,600 ****
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				arg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (arg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(arg);
  			}
  #endif
--- 594,602 ----
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				uarg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (uarg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(uarg);
  			}
  #endif
***************
*** 623,632 ****
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				arg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (arg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(arg);
! 				*q = PyString_GET_SIZE(arg);
  			}
  #endif
--- 625,634 ----
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				uarg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (uarg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(uarg);
! 				*q = PyString_GET_SIZE(uarg);
  			}
  #endif
***************
*** 649,657 ****
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				arg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (arg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(arg);
  			}
  #endif
--- 651,659 ----
  #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
! 				uarg = UNICODE_DEFAULT_ENCODING(arg);
! 				if (uarg == NULL)
  					return converterr(CONV_UNICODE,
  							  arg, msgbuf);
! 				*p = PyString_AS_STRING(uarg);
  			}
  #endif