[Python-checkins] CVS: python/dist/src/Modules _hotshot.c,1.9,1.10 _localemodule.c,2.24,2.25 _testcapimodule.c,1.13,1.14 _tkinter.c,1.119,1.120 arraymodule.c,2.64,2.65 flmodule.c,1.45,1.46 gdbmmodule.c,2.30,2.31 pcremodule.c,2.28,2.29 posixmodule.c,2.209,2.210 pyexpat.c,2.55,2.56 readline.c,2.40,2.41 socketmodule.c,1.197,1.198 stropmodule.c,2.82,2.83

Tim Peters tim_one@users.sourceforge.net
Wed, 28 Nov 2001 12:27:44 -0800


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

Modified Files:
	_hotshot.c _localemodule.c _testcapimodule.c _tkinter.c 
	arraymodule.c flmodule.c gdbmmodule.c pcremodule.c 
	posixmodule.c pyexpat.c readline.c socketmodule.c 
	stropmodule.c 
Log Message:
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Also changed <>-style #includes to ""-style in some places where the
former didn't make sense.


Index: _hotshot.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_hotshot.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** _hotshot.c	2001/11/09 15:59:36	1.9
--- _hotshot.c	2001/11/28 20:27:42	1.10
***************
*** 3,11 ****
   */
  
! #include <Python.h>
! #include <compile.h>
! #include <eval.h>
! #include <frameobject.h>
! #include <structmember.h>
  
  #ifdef HAVE_UNISTD_H
--- 3,11 ----
   */
  
! #include "Python.h"
! #include "compile.h"
! #include "eval.h"
! #include "frameobject.h"
! #include "structmember.h"
  
  #ifdef HAVE_UNISTD_H
***************
*** 1453,1462 ****
  
  #ifdef MS_WIN32
!     sprintf(cwdbuffer, "%I64d", frequency.QuadPart);
      pack_add_info(self, "reported-performance-frequency", cwdbuffer);
  #else
!     sprintf(cwdbuffer, "%lu", rusage_diff);
      pack_add_info(self, "observed-interval-getrusage", cwdbuffer);
!     sprintf(cwdbuffer, "%lu", timeofday_diff);
      pack_add_info(self, "observed-interval-gettimeofday", cwdbuffer);
  #endif
--- 1453,1462 ----
  
  #ifdef MS_WIN32
!     PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%I64d", frequency.QuadPart);
      pack_add_info(self, "reported-performance-frequency", cwdbuffer);
  #else
!     PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", rusage_diff);
      pack_add_info(self, "observed-interval-getrusage", cwdbuffer);
!     PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", timeofday_diff);
      pack_add_info(self, "observed-interval-gettimeofday", cwdbuffer);
  #endif

Index: _localemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_localemodule.c,v
retrieving revision 2.24
retrieving revision 2.25
diff -C2 -d -r2.24 -r2.25
*** _localemodule.c	2001/09/20 19:18:30	2.24
--- _localemodule.c	2001/11/28 20:27:42	2.25
***************
*** 377,381 ****
          return NULL;
  
!     sprintf(encoding, "cp%d", GetACP());
  
      if (GetLocaleInfo(LOCALE_USER_DEFAULT,
--- 377,381 ----
          return NULL;
  
!     PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
  
      if (GetLocaleInfo(LOCALE_USER_DEFAULT,

Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** _testcapimodule.c	2001/11/28 11:46:59	1.13
--- _testcapimodule.c	2001/11/28 20:27:42	1.14
***************
*** 20,24 ****
  		PyErr_SetString(TestError, "internal error msg too large");
  	else {
! 		sprintf(buf, "%s: %s", test_name, msg);
  		PyErr_SetString(TestError, buf);
  	}
--- 20,24 ----
  		PyErr_SetString(TestError, "internal error msg too large");
  	else {
! 		PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
  		PyErr_SetString(TestError, buf);
  	}
***************
*** 37,41 ****
  {
  	char buf[1024];
! 	sprintf(buf, "%.200s #define == %d but sizeof(%.200s) == %d",
  		fatname, expected, typename, got);
  	PyErr_SetString(TestError, buf);
--- 37,42 ----
  {
  	char buf[1024];
! 	PyOS_snprintf(buf, sizeof(buf), 
! 		"%.200s #define == %d but sizeof(%.200s) == %d",
  		fatname, expected, typename, got);
  	PyErr_SetString(TestError, buf);

Index: _tkinter.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.119
retrieving revision 1.120
diff -C2 -d -r1.119 -r1.120
*** _tkinter.c	2001/08/17 18:39:25	1.119
--- _tkinter.c	2001/11/28 20:27:42	1.120
***************
*** 1580,1585 ****
  	char buf[100];
  
! 	sprintf(buf, "<tktimertoken at %p%s>", v,
! 		v->func == NULL ? ", handler deleted" : "");
  	return PyString_FromString(buf);
  }
--- 1580,1585 ----
  	char buf[100];
  
! 	PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
! 		      v->func == NULL ? ", handler deleted" : "");
  	return PyString_FromString(buf);
  }

Index: arraymodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v
retrieving revision 2.64
retrieving revision 2.65
diff -C2 -d -r2.64 -r2.65
*** arraymodule.c	2001/07/27 16:05:32	2.64
--- arraymodule.c	2001/11/28 20:27:42	2.65
***************
*** 1314,1323 ****
  	len = a->ob_size;
  	if (len == 0) {
! 		sprintf(buf, "array('%c')", a->ob_descr->typecode);
  		return PyString_FromString(buf);
  	}
  	if (a->ob_descr->typecode == 'c') {
  		PyObject *t_empty = PyTuple_New(0);
! 		sprintf(buf, "array('c', ");
  		s = PyString_FromString(buf);
  		v = array_tostring(a, t_empty);
--- 1314,1324 ----
  	len = a->ob_size;
  	if (len == 0) {
! 		PyOS_snprintf(buf, sizeof(buf), "array('%c')",
! 			      a->ob_descr->typecode);
  		return PyString_FromString(buf);
  	}
  	if (a->ob_descr->typecode == 'c') {
  		PyObject *t_empty = PyTuple_New(0);
! 		PyOS_snprintf(buf, sizeof(buf), "array('c', ");
  		s = PyString_FromString(buf);
  		v = array_tostring(a, t_empty);
***************
*** 1329,1333 ****
  		return s;
  	}
! 	sprintf(buf, "array('%c', [", a->ob_descr->typecode);
  	s = PyString_FromString(buf);
  	comma = PyString_FromString(", ");
--- 1330,1334 ----
  		return s;
  	}
! 	PyOS_snprintf(buf, sizeof(buf), "array('%c', [", a->ob_descr->typecode);
  	s = PyString_FromString(buf);
  	comma = PyString_FromString(", ");

Index: flmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/flmodule.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** flmodule.c	2000/09/01 23:29:26	1.45
--- flmodule.c	2001/11/28 20:27:42	1.46
***************
*** 371,376 ****
  {
  	char buf[100];
! 	sprintf(buf, "<FORMS_object at %p, objclass=%d>",
! 		g, g->ob_generic->objclass);
  	return PyString_FromString(buf);
  }
--- 371,376 ----
  {
  	char buf[100];
! 	PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
! 		      g, g->ob_generic->objclass);
  	return PyString_FromString(buf);
  }
***************
*** 1581,1586 ****
  {
  	char buf[100];
! 	sprintf(buf, "<FORMS_form at %p, window=%ld>",
! 		f, f->ob_form->window);
  	return PyString_FromString(buf);
  }
--- 1581,1586 ----
  {
  	char buf[100];
! 	PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
! 		      f, f->ob_form->window);
  	return PyString_FromString(buf);
  }

Index: gdbmmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/gdbmmodule.c,v
retrieving revision 2.30
retrieving revision 2.31
diff -C2 -d -r2.30 -r2.31
*** gdbmmodule.c	2001/11/11 14:24:05	2.30
--- gdbmmodule.c	2001/11/28 20:27:42	2.31
***************
*** 478,482 ****
  #endif
              default:
!                 sprintf(buf, "Flag '%c' is not supported.", *flags);
                  PyErr_SetString(DbmError, buf);
                  return NULL;
--- 478,483 ----
  #endif
              default:
!                 PyOS_snprintf(buf, sizeof(buf), "Flag '%c' is not supported.",
!                 	      *flags);
                  PyErr_SetString(DbmError, buf);
                  return NULL;

Index: pcremodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pcremodule.c,v
retrieving revision 2.28
retrieving revision 2.29
diff -C2 -d -r2.28 -r2.29
*** pcremodule.c	2001/07/19 21:29:48	2.28
--- pcremodule.c	2001/11/28 20:27:42	2.29
***************
*** 264,268 ****
  	{
  		char message[50];
! 		sprintf(message, "\\%c is not allowed", c);
  		PyErr_SetString(ErrorObject, message);
  		return NULL;
--- 264,269 ----
  	{
  		char message[50];
! 		PyOS_snprintf(message, sizeof(message),
! 			      "\\%c is not allowed", c);
  		PyErr_SetString(ErrorObject, message);
  		return NULL;
***************
*** 496,500 ****
  				{
  					char message[50];
! 					sprintf(message, 
  						"group did not contribute to the match");
  					PyErr_SetString(ErrorObject, 
--- 497,501 ----
  				{
  					char message[50];
! 					PyOS_snprintf(message, sizeof(message),
  						"group did not contribute to the match");
  					PyErr_SetString(ErrorObject, 

Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.209
retrieving revision 2.210
diff -C2 -d -r2.209 -r2.210
*** posixmodule.c	2001/11/28 11:46:59	2.209
--- posixmodule.c	2001/11/28 20:27:42	2.210
***************
*** 433,437 ****
          os2_formatmsg(msgbuf, msglen, reason);
      else
!         sprintf(msgbuf, "unknown OS error #%d", errorcode);
  
      return msgbuf;
--- 433,438 ----
          os2_formatmsg(msgbuf, msglen, reason);
      else
!         PyOS_snprintf(msgbuf, sizeof(msgbuf),
!         	      "unknown OS error #%d", errorcode);
  
      return msgbuf;
***************
*** 5815,5820 ****
      case 50: ver = "5.00"; break;
      default:
!         sprintf(tmp, "%d-%d", values[QSV_VERSION_MAJOR],
!                               values[QSV_VERSION_MINOR]);
          ver = &tmp[0];
      }
--- 5816,5822 ----
      case 50: ver = "5.00"; break;
      default:
!         PyOS_snprintf(tmp, sizeof(tmp),
!         	      "%d-%d", values[QSV_VERSION_MAJOR],
!                       values[QSV_VERSION_MINOR]);
          ver = &tmp[0];
      }

Index: pyexpat.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pyexpat.c,v
retrieving revision 2.55
retrieving revision 2.56
diff -C2 -d -r2.55 -r2.56
*** pyexpat.c	2001/11/18 02:36:07	2.55
--- pyexpat.c	2001/11/28 20:27:42	2.56
***************
*** 130,134 ****
      enum XML_Error code = XML_GetErrorCode(parser);
  
!     sprintf(buffer, "%.200s: line %i, column %i",
              XML_ErrorString(code), lineno, column);
      err = PyObject_CallFunction(ErrorObject, "s", buffer);
--- 130,134 ----
      enum XML_Error code = XML_GetErrorCode(parser);
  
!     PyOS_snprintf(buffer, sizeof(buffer), "%.200s: line %i, column %i",
              XML_ErrorString(code), lineno, column);
      err = PyObject_CallFunction(ErrorObject, "s", buffer);

Index: readline.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v
retrieving revision 2.40
retrieving revision 2.41
diff -C2 -d -r2.40 -r2.41
*** readline.c	2001/11/28 11:46:59	2.40
--- readline.c	2001/11/28 20:27:42	2.41
***************
*** 166,170 ****
  	PyObject *function = Py_None;
  	char buf[80];
! 	sprintf(buf, "|O:set_%.50s", funcname);
  	if (!PyArg_ParseTuple(args, buf, &function))
  		return NULL;
--- 166,170 ----
  	PyObject *function = Py_None;
  	char buf[80];
! 	PyOS_snprintf(buf, sizeof(buf), "|O:set_%.50s", funcname);
  	if (!PyArg_ParseTuple(args, buf, &function))
  		return NULL;
***************
*** 182,186 ****
  	}
  	else {
! 		sprintf(buf, "set_%.50s(func): argument not callable", funcname);
  		PyErr_SetString(PyExc_TypeError, buf);
  		return NULL;
--- 182,188 ----
  	}
  	else {
! 		PyOS_snprintf(buf, sizeof(buf),
! 			      "set_%.50s(func): argument not callable",
! 			      funcname);
  		PyErr_SetString(PyExc_TypeError, buf);
  		return NULL;

Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.197
retrieving revision 1.198
diff -C2 -d -r1.197 -r1.198
*** socketmodule.c	2001/11/28 04:28:31	1.197
--- socketmodule.c	2001/11/28 20:27:42	1.198
***************
*** 1769,1775 ****
  	}
  #endif
! 	sprintf(buf,
! 		"<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
! 		(long)s->sock_fd, s->sock_family, s->sock_type, s->sock_proto);
  	return PyString_FromString(buf);
  }
--- 1769,1777 ----
  	}
  #endif
! 	PyOS_snprintf(buf, sizeof(buf),
! 		      "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
! 		      (long)s->sock_fd, s->sock_family,
! 		      s->sock_type,
! 		      s->sock_proto);
  	return PyString_FromString(buf);
  }
***************
*** 3057,3061 ****
  		break;
  	default:
! 		sprintf(buf, "WSAStartup failed: error code %d", ret);
  		PyErr_SetString(PyExc_ImportError, buf);
  		break;
--- 3059,3064 ----
  		break;
  	default:
! 		PyOS_snprintf(buf, sizeof(buf),
! 			      "WSAStartup failed: error code %d", ret);
  		PyErr_SetString(PyExc_ImportError, buf);
  		break;

Index: stropmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/stropmodule.c,v
retrieving revision 2.82
retrieving revision 2.83
diff -C2 -d -r2.82 -r2.83
*** stropmodule.c	2001/05/15 02:14:44	2.82
--- stropmodule.c	2001/11/28 20:27:42	2.83
***************
*** 773,777 ****
  	if (*end != '\0') {
    bad:
! 		sprintf(buffer, "invalid literal for atoi(): %.200s", s);
  		PyErr_SetString(PyExc_ValueError, buffer);
  		return NULL;
--- 773,778 ----
  	if (*end != '\0') {
    bad:
! 		PyOS_snprintf(buffer, sizeof(buffer),
! 			      "invalid literal for atoi(): %.200s", s);
  		PyErr_SetString(PyExc_ValueError, buffer);
  		return NULL;
***************
*** 866,875 ****
  		end++;
  	if (*end != '\0') {
! 		sprintf(buffer, "invalid literal for atof(): %.200s", s);
  		PyErr_SetString(PyExc_ValueError, buffer);
  		return NULL;
  	}
  	else if (errno != 0) {
! 		sprintf(buffer, "atof() literal too large: %.200s", s);
  		PyErr_SetString(PyExc_ValueError, buffer);
  		return NULL;
--- 867,878 ----
  		end++;
  	if (*end != '\0') {
! 		PyOS_snprintf(buffer, sizeof(buffer),
! 			      "invalid literal for atof(): %.200s", s);
  		PyErr_SetString(PyExc_ValueError, buffer);
  		return NULL;
  	}
  	else if (errno != 0) {
! 		PyOS_snprintf(buffer, sizeof(buffer), 
! 			      "atof() literal too large: %.200s", s);
  		PyErr_SetString(PyExc_ValueError, buffer);
  		return NULL;