[Python-checkins] CVS: python/dist/src/Python getargs.c,2.76,2.77

Tim Peters tim_one@users.sourceforge.net
Fri, 26 Oct 2001 22:07:43 -0700


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

Modified Files:
	getargs.c 
Log Message:
vgetargskeywords:
+ Generally test nkeywords against 0 instead of keywords against NULL
  (saves a little work if an empty keywords dict is passed, and is
  conceptually more on-target regardless).
+ When a call erroneously specifies a keyword argument both by position
  and by keyword name:
    - It was easy to provoke this routine into an internal buffer overrun
      by using a long argument name.  Now uses PyErr_format instead (which
      computes a safe buffer size).
    - Improved the error msg.


Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.76
retrieving revision 2.77
diff -C2 -d -r2.76 -r2.77
*** getargs.c	2001/10/27 04:45:34	2.76
--- getargs.c	2001/10/27 05:07:41	2.77
***************
*** 1086,1090 ****
  	   its not clear when to use the term "keyword argument vs. 
  	   keyword parameter in messages */
! 	if (keywords) {
  		for (i = 0; i < nargs; i++) {
  			char *thiskw = kwlist[i];
--- 1086,1090 ----
  	   its not clear when to use the term "keyword argument vs. 
  	   keyword parameter in messages */
! 	if (nkeywords > 0) {
  		for (i = 0; i < nargs; i++) {
  			char *thiskw = kwlist[i];
***************
*** 1092,1099 ****
  				break;
  			if (PyMapping_HasKeyString(keywords, thiskw)) {
! 				sprintf(msgbuf,
! 					"keyword parameter %s redefined",
  					thiskw);
- 				PyErr_SetString(PyExc_TypeError, msgbuf);
  				return 0;
  			}
--- 1092,1099 ----
  				break;
  			if (PyMapping_HasKeyString(keywords, thiskw)) {
! 				PyErr_Format(PyExc_TypeError,
! 					"keyword parameter '%s' was given "
! 					"by position and by name",
  					thiskw);
  				return 0;
  			}
***************
*** 1156,1173 ****
  
  	/* handle no keyword parameters in call  */	
! 	   	   
! 	if (!keywords)
  		return 1; 
! 		
  	/* make sure the number of keywords in the keyword list matches the 
  	   number of items in the format string */
- 	  
  	nkwlist = 0;
  	p =  kwlist;
! 	for (;;) {
! 		if (!*(p++)) break;
  		nkwlist++;
- 	}
- 
  	if (nkwlist != max) {
  		PyErr_SetString(PyExc_SystemError,
--- 1156,1168 ----
  
  	/* handle no keyword parameters in call  */	
! 	if (nkeywords == 0)
  		return 1; 
! 
  	/* make sure the number of keywords in the keyword list matches the 
  	   number of items in the format string */
  	nkwlist = 0;
  	p =  kwlist;
! 	while (*p++)
  		nkwlist++;
  	if (nkwlist != max) {
  		PyErr_SetString(PyExc_SystemError,
***************
*** 1175,1182 ****
  		return 0;
  	}	  	  
! 			
  	/* convert the keyword arguments; this uses the format 
  	   string where it was left after processing args */
- 	
  	converted = 0;
  	for (i = nargs; i < nkwlist; i++) {
--- 1170,1176 ----
  		return 0;
  	}	  	  
! 		
  	/* convert the keyword arguments; this uses the format 
  	   string where it was left after processing args */
  	converted = 0;
  	for (i = nargs; i < nkwlist; i++) {
***************
*** 1203,1209 ****
  		}
  	}
! 	
  	/* make sure there are no extraneous keyword arguments */
- 	
  	pos = 0;
  	if (converted < nkeywords) {
--- 1197,1202 ----
  		}
  	}
! 
  	/* make sure there are no extraneous keyword arguments */
  	pos = 0;
  	if (converted < nkeywords) {