[Python-checkins] CVS: python/dist/src/Python getargs.c,2.86,2.87

Jeremy Hylton jhylton@users.sourceforge.net
Wed, 28 Nov 2001 13:47:01 -0800


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

Modified Files:
	getargs.c 
Log Message:
Use PyOS_snprintf() at some cost even though it was correct before.

seterror() uses a char array and a pointer to the current position in
that array.  Use snprintf() and compute the amount of space left in
the buffer based on the current pointer position.




Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.86
retrieving revision 2.87
diff -C2 -d -r2.86 -r2.87
*** getargs.c	2001/11/28 20:29:22	2.86
--- getargs.c	2001/11/28 21:46:59	2.87
***************
*** 225,239 ****
  		return;
  	else if (message == NULL) {
- 		/* XXX snprintf */
  		if (fname != NULL) {
! 			sprintf(p, "%.200s() ", fname);
  			p += strlen(p);
  		}
  		if (iarg != 0) {
! 			sprintf(p, "argument %d", iarg);
  			i = 0;
  			p += strlen(p);
  			while (levels[i] > 0 && (int)(p-buf) < 220) {
! 				sprintf(p, ", item %d", levels[i]-1);
  				p += strlen(p);
  				i++;
--- 225,240 ----
  		return;
  	else if (message == NULL) {
  		if (fname != NULL) {
! 			PyOS_snprintf(p, sizeof(buf), "%.200s() ", fname);
  			p += strlen(p);
  		}
  		if (iarg != 0) {
! 			PyOS_snprintf(p, sizeof(buf) - (buf - p),
! 				      "argument %d", iarg);
  			i = 0;
  			p += strlen(p);
  			while (levels[i] > 0 && (int)(p-buf) < 220) {
! 				PyOS_snprintf(p, sizeof(buf) - (buf - p),
! 					      ", item %d", levels[i]-1);
  				p += strlen(p);
  				i++;
***************
*** 241,248 ****
  		}
  		else {
! 			sprintf(p, "argument");
  			p += strlen(p);
  		}
! 		sprintf(p, " %.256s", msg);
  		message = buf;
  	}
--- 242,249 ----
  		}
  		else {
! 			PyOS_snprintf(p, sizeof(buf) - (buf - p), "argument");
  			p += strlen(p);
  		}
! 		PyOS_snprintf(p, sizeof(buf) - (buf - p), " %.256s", msg);
  		message = buf;
  	}