summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-11-28 20:27:42 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-11-28 20:27:42 (GMT)
commit885d457709c1d680c899dc3d035a47c8fb514cfa (patch)
treed16b3a6f89208a1b46b786958a316ef9075d3fab /Modules
parent05bd787c6cd55f29d43465de621778221e0fc46e (diff)
downloadcpython-885d457709c1d680c899dc3d035a47c8fb514cfa.zip
cpython-885d457709c1d680c899dc3d035a47c8fb514cfa.tar.gz
cpython-885d457709c1d680c899dc3d035a47c8fb514cfa.tar.bz2
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Also changed <>-style #includes to ""-style in some places where the former didn't make sense.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_hotshot.c16
-rw-r--r--Modules/_localemodule.c2
-rw-r--r--Modules/_testcapimodule.c5
-rw-r--r--Modules/_tkinter.c4
-rw-r--r--Modules/arraymodule.c7
-rw-r--r--Modules/flmodule.c8
-rw-r--r--Modules/gdbmmodule.c3
-rw-r--r--Modules/pcremodule.c5
-rw-r--r--Modules/posixmodule.c8
-rw-r--r--Modules/pyexpat.c2
-rw-r--r--Modules/readline.c6
-rw-r--r--Modules/socketmodule.c11
-rw-r--r--Modules/stropmodule.c9
13 files changed, 50 insertions, 36 deletions
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 3b8d616..deaf9dd 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -2,11 +2,11 @@
* This is the High Performance Python Profiler portion of HotShot.
*/
-#include <Python.h>
-#include <compile.h>
-#include <eval.h>
-#include <frameobject.h>
-#include <structmember.h>
+#include "Python.h"
+#include "compile.h"
+#include "eval.h"
+#include "frameobject.h"
+#include "structmember.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -1452,12 +1452,12 @@ write_header(ProfilerObject *self)
pack_add_info(self, "executable-version", buffer);
#ifdef MS_WIN32
- sprintf(cwdbuffer, "%I64d", frequency.QuadPart);
+ PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%I64d", frequency.QuadPart);
pack_add_info(self, "reported-performance-frequency", cwdbuffer);
#else
- sprintf(cwdbuffer, "%lu", rusage_diff);
+ PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", rusage_diff);
pack_add_info(self, "observed-interval-getrusage", cwdbuffer);
- sprintf(cwdbuffer, "%lu", timeofday_diff);
+ PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", timeofday_diff);
pack_add_info(self, "observed-interval-gettimeofday", cwdbuffer);
#endif
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index 61a5c7c..d96a967 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -376,7 +376,7 @@ PyLocale_getdefaultlocale(PyObject* self, PyObject* args)
if (!PyArg_NoArgs(args))
return NULL;
- sprintf(encoding, "cp%d", GetACP());
+ PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO639LANGNAME,
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 01e103b..0f5fa7c 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -19,7 +19,7 @@ raiseTestError(const char* test_name, const char* msg)
if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
PyErr_SetString(TestError, "internal error msg too large");
else {
- sprintf(buf, "%s: %s", test_name, msg);
+ PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
PyErr_SetString(TestError, buf);
}
return NULL;
@@ -36,7 +36,8 @@ sizeof_error(const char* fatname, const char* typename,
int expected, int got)
{
char buf[1024];
- sprintf(buf, "%.200s #define == %d but sizeof(%.200s) == %d",
+ PyOS_snprintf(buf, sizeof(buf),
+ "%.200s #define == %d but sizeof(%.200s) == %d",
fatname, expected, typename, got);
PyErr_SetString(TestError, buf);
return (PyObject*)NULL;
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index eedb0c1..4e701ad 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -1579,8 +1579,8 @@ Tktt_Repr(PyObject *self)
TkttObject *v = (TkttObject *)self;
char buf[100];
- sprintf(buf, "<tktimertoken at %p%s>", v,
- v->func == NULL ? ", handler deleted" : "");
+ PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
+ v->func == NULL ? ", handler deleted" : "");
return PyString_FromString(buf);
}
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 6168bb0..11d0723 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1313,12 +1313,13 @@ array_repr(arrayobject *a)
int i, len;
len = a->ob_size;
if (len == 0) {
- sprintf(buf, "array('%c')", a->ob_descr->typecode);
+ 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);
- sprintf(buf, "array('c', ");
+ PyOS_snprintf(buf, sizeof(buf), "array('c', ");
s = PyString_FromString(buf);
v = array_tostring(a, t_empty);
Py_DECREF(t_empty);
@@ -1328,7 +1329,7 @@ array_repr(arrayobject *a)
PyString_ConcatAndDel(&s, PyString_FromString(")"));
return s;
}
- sprintf(buf, "array('%c', [", a->ob_descr->typecode);
+ PyOS_snprintf(buf, sizeof(buf), "array('%c', [", a->ob_descr->typecode);
s = PyString_FromString(buf);
comma = PyString_FromString(", ");
for (i = 0; i < len && !PyErr_Occurred(); i++) {
diff --git a/Modules/flmodule.c b/Modules/flmodule.c
index ef853f5..25037bf 100644
--- a/Modules/flmodule.c
+++ b/Modules/flmodule.c
@@ -370,8 +370,8 @@ static PyObject *
generic_repr(genericobject *g)
{
char buf[100];
- sprintf(buf, "<FORMS_object at %p, objclass=%d>",
- g, g->ob_generic->objclass);
+ PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
+ g, g->ob_generic->objclass);
return PyString_FromString(buf);
}
@@ -1580,8 +1580,8 @@ static PyObject *
form_repr(formobject *f)
{
char buf[100];
- sprintf(buf, "<FORMS_form at %p, window=%ld>",
- f, f->ob_form->window);
+ PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
+ f, f->ob_form->window);
return PyString_FromString(buf);
}
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index 0190a9b..505ce92 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -477,7 +477,8 @@ dbmopen(PyObject *self, PyObject *args)
break;
#endif
default:
- sprintf(buf, "Flag '%c' is not supported.", *flags);
+ PyOS_snprintf(buf, sizeof(buf), "Flag '%c' is not supported.",
+ *flags);
PyErr_SetString(DbmError, buf);
return NULL;
}
diff --git a/Modules/pcremodule.c b/Modules/pcremodule.c
index e34c002..7a8900d 100644
--- a/Modules/pcremodule.c
+++ b/Modules/pcremodule.c
@@ -263,7 +263,8 @@ PyPcre_expand_escape(unsigned char *pattern, int pattern_len,
case('U'): case('l'): case('u'):
{
char message[50];
- sprintf(message, "\\%c is not allowed", c);
+ PyOS_snprintf(message, sizeof(message),
+ "\\%c is not allowed", c);
PyErr_SetString(ErrorObject, message);
return NULL;
}
@@ -495,7 +496,7 @@ PyPcre_expand(PyObject *self, PyObject *args)
if (result==Py_None)
{
char message[50];
- sprintf(message,
+ PyOS_snprintf(message, sizeof(message),
"group did not contribute to the match");
PyErr_SetString(ErrorObject,
message);
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 27e7f1a..365a836 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -432,7 +432,8 @@ os2_strerror(char *msgbuf, int msgbuflen, int errorcode, char *reason)
if (rc == NO_ERROR)
os2_formatmsg(msgbuf, msglen, reason);
else
- sprintf(msgbuf, "unknown OS error #%d", errorcode);
+ PyOS_snprintf(msgbuf, sizeof(msgbuf),
+ "unknown OS error #%d", errorcode);
return msgbuf;
}
@@ -5814,8 +5815,9 @@ static int insertvalues(PyObject *d)
case 40: ver = "4.00"; break;
case 50: ver = "5.00"; break;
default:
- sprintf(tmp, "%d-%d", values[QSV_VERSION_MAJOR],
- values[QSV_VERSION_MINOR]);
+ PyOS_snprintf(tmp, sizeof(tmp),
+ "%d-%d", values[QSV_VERSION_MAJOR],
+ values[QSV_VERSION_MINOR]);
ver = &tmp[0];
}
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index dada234..90e53b6 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -129,7 +129,7 @@ set_error(xmlparseobject *self)
int column = XML_GetErrorColumnNumber(parser);
enum XML_Error code = XML_GetErrorCode(parser);
- sprintf(buffer, "%.200s: line %i, column %i",
+ PyOS_snprintf(buffer, sizeof(buffer), "%.200s: line %i, column %i",
XML_ErrorString(code), lineno, column);
err = PyObject_CallFunction(ErrorObject, "s", buffer);
if ( err != NULL
diff --git a/Modules/readline.c b/Modules/readline.c
index d213992..fe653b8 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -165,7 +165,7 @@ set_hook(const char * funcname, PyObject **hook_var, PyThreadState **tstate, PyO
{
PyObject *function = Py_None;
char buf[80];
- sprintf(buf, "|O:set_%.50s", funcname);
+ PyOS_snprintf(buf, sizeof(buf), "|O:set_%.50s", funcname);
if (!PyArg_ParseTuple(args, buf, &function))
return NULL;
if (function == Py_None) {
@@ -181,7 +181,9 @@ set_hook(const char * funcname, PyObject **hook_var, PyThreadState **tstate, PyO
*tstate = PyThreadState_Get();
}
else {
- sprintf(buf, "set_%.50s(func): argument not callable", funcname);
+ PyOS_snprintf(buf, sizeof(buf),
+ "set_%.50s(func): argument not callable",
+ funcname);
PyErr_SetString(PyExc_TypeError, buf);
return NULL;
}
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 2b27e71..eccee4d 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1768,9 +1768,11 @@ PySocketSock_repr(PySocketSockObject *s)
return NULL;
}
#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);
+ 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);
}
@@ -3056,7 +3058,8 @@ NTinit(void)
"WSAStartup failed: requested version not supported");
break;
default:
- sprintf(buf, "WSAStartup failed: error code %d", ret);
+ PyOS_snprintf(buf, sizeof(buf),
+ "WSAStartup failed: error code %d", ret);
PyErr_SetString(PyExc_ImportError, buf);
break;
}
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index bd56ee0..3c5de2b 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -772,7 +772,8 @@ strop_atoi(PyObject *self, PyObject *args)
end++;
if (*end != '\0') {
bad:
- sprintf(buffer, "invalid literal for atoi(): %.200s", s);
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "invalid literal for atoi(): %.200s", s);
PyErr_SetString(PyExc_ValueError, buffer);
return NULL;
}
@@ -865,12 +866,14 @@ strop_atof(PyObject *self, PyObject *args)
while (*end && isspace(Py_CHARMASK(*end)))
end++;
if (*end != '\0') {
- sprintf(buffer, "invalid literal for atof(): %.200s", s);
+ PyOS_snprintf(buffer, sizeof(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);
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "atof() literal too large: %.200s", s);
PyErr_SetString(PyExc_ValueError, buffer);
return NULL;
}