diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-11-28 20:42:20 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-11-28 20:42:20 (GMT) |
commit | 518ab1c02a01a1a502fedeccb62ea73f2a952ba7 (patch) | |
tree | 4fd0238c7960f0001e8b576656acbbbe0947053e /Python | |
parent | ef58b319916f6cf2034acc40b411f8405f20416f (diff) | |
download | cpython-518ab1c02a01a1a502fedeccb62ea73f2a952ba7.zip cpython-518ab1c02a01a1a502fedeccb62ea73f2a952ba7.tar.gz cpython-518ab1c02a01a1a502fedeccb62ea73f2a952ba7.tar.bz2 |
Use PyOS_snprintf instead of sprintf.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 2 | ||||
-rw-r--r-- | Python/dynload_dl.c | 2 | ||||
-rw-r--r-- | Python/dynload_hpux.c | 5 | ||||
-rw-r--r-- | Python/dynload_mac.c | 16 | ||||
-rw-r--r-- | Python/dynload_next.c | 2 | ||||
-rw-r--r-- | Python/dynload_os2.c | 8 | ||||
-rw-r--r-- | Python/dynload_shlib.c | 5 | ||||
-rw-r--r-- | Python/dynload_win.c | 26 | ||||
-rw-r--r-- | Python/getversion.c | 4 | ||||
-rw-r--r-- | Python/pythonrun.c | 2 | ||||
-rw-r--r-- | Python/strerror.c | 3 | ||||
-rw-r--r-- | Python/traceback.c | 2 |
12 files changed, 42 insertions, 35 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index b6e4460..8e4ca2e 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -779,7 +779,7 @@ builtin_map(PyObject *self, PyObject *args) static char errmsg[] = "argument %d to map() must support iteration"; char errbuf[sizeof(errmsg) + 25]; - sprintf(errbuf, errmsg, i+2); + PyOS_snprintf(errbuf, sizeof(errbuf), errmsg, i+2); PyErr_SetString(PyExc_TypeError, errbuf); goto Fail_2; } diff --git a/Python/dynload_dl.c b/Python/dynload_dl.c index 5a62d6f..4675a67 100644 --- a/Python/dynload_dl.c +++ b/Python/dynload_dl.c @@ -21,6 +21,6 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, { char funcname[258]; - sprintf(funcname, "init%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); return dl_loadmod(Py_GetProgramName(), pathname, funcname); } diff --git a/Python/dynload_hpux.c b/Python/dynload_hpux.c index e435cd8..cbdb35a 100644 --- a/Python/dynload_hpux.c +++ b/Python/dynload_hpux.c @@ -39,11 +39,12 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, char buf[256]; if (Py_VerboseFlag) perror(pathname); - sprintf(buf, "Failed to load %.200s", pathname); + PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s", + pathname); PyErr_SetString(PyExc_ImportError, buf); return NULL; } - sprintf(funcname, FUNCNAME_PATTERN, shortname); + PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, shortname); if (Py_VerboseFlag) printf("shl_findsym %s\n", funcname); shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p); diff --git a/Python/dynload_mac.c b/Python/dynload_mac.c index c8c9646..bb5f4fb 100644 --- a/Python/dynload_mac.c +++ b/Python/dynload_mac.c @@ -66,7 +66,8 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething); #endif if ( err ) { - sprintf(buf, "%.200s: %.200s", pathname, PyMac_StrError(err)); + PyOS_snprintf(buf, sizeof(buf), + "%.200s: %.200s", pathname, PyMac_StrError(err)); PyErr_SetString(PyExc_ImportError, buf); return NULL; } @@ -91,25 +92,26 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, ** the dynamic module was meant for a different Python. */ if (errMessage[0] == 10 && strncmp((char *)errMessage+1, "PythonCore", 10) == 0 ) { - sprintf(buf, "Dynamic module was built for %s version of MacPython", - (err == cfragImportTooOldErr ? "a newer" : "an older")); + PyOS_snprintf(buf, sizeof(buf), + "Dynamic module was built for %s version of MacPython", + (err == cfragImportTooOldErr ? "a newer" : "an older")); PyErr_SetString(PyExc_ImportError, buf); return NULL; } } if ( err ) { - sprintf(buf, "%.*s: %.200s", + PyOS_snprintf(buf, sizeof(buf), "%.*s: %.200s", errMessage[0], errMessage+1, PyMac_StrError(err)); PyErr_SetString(PyExc_ImportError, buf); return NULL; } /* Locate the address of the correct init function */ - sprintf(funcname, "init%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); err = FindSymbol(connID, Pstring(funcname), &symAddr, &class); if ( err ) { - sprintf(buf, "%s: %.200s", - funcname, PyMac_StrError(err)); + PyOS_snprintf(buf, sizeof(buf), "%s: %.200s", + funcname, PyMac_StrError(err)); PyErr_SetString(PyExc_ImportError, buf); return NULL; } diff --git a/Python/dynload_next.c b/Python/dynload_next.c index 2b34315..671b26f 100644 --- a/Python/dynload_next.c +++ b/Python/dynload_next.c @@ -44,7 +44,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, dl_funcptr p = NULL; char funcname[258]; - sprintf(funcname, "_init%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), "_init%.200s", shortname); #ifdef USE_RLD { diff --git a/Python/dynload_os2.c b/Python/dynload_os2.c index a3eb468..d660e27 100644 --- a/Python/dynload_os2.c +++ b/Python/dynload_os2.c @@ -31,14 +31,14 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, if (rc != NO_ERROR) { char errBuf[256]; - sprintf(errBuf, - "DLL load failed, rc = %d: %.200s", - rc, failreason); + PyOS_snprintf(errBuf, sizeof(errBuf), + "DLL load failed, rc = %d: %.200s", + rc, failreason); PyErr_SetString(PyExc_ImportError, errBuf); return NULL; } - sprintf(funcname, "init%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); rc = DosQueryProcAddr(hDLL, 0L, funcname, &p); if (rc != NO_ERROR) p = NULL; /* Signify Failure to Acquire Entrypoint */ diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index 569a6f5..e8a04ce 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -57,11 +57,12 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, if (strchr(pathname, '/') == NULL) { /* Prefix bare filename with "./" */ - sprintf(pathbuf, "./%-.255s", pathname); + PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); pathname = pathbuf; } - sprintf(funcname, LEAD_UNDERSCORE "init%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), + LEAD_UNDERSCORE "init%.200s", shortname); if (fp != NULL) { int i; diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 155a9d6..9062cf3 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -159,7 +159,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, dl_funcptr p; char funcname[258], *import_python; - sprintf(funcname, "init%.200s", shortname); + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); #ifdef MS_WIN32 { @@ -201,9 +201,9 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, /* Problem: could not get the error message. This should not happen if called correctly. */ if (theLength == 0) { - sprintf(errBuf, - "DLL load failed with error code %d", - errorCode); + PyOS_snprintf(errBuf, sizeof(errBuf), + "DLL load failed with error code %d", + errorCode); } else { size_t len; /* For some reason a \r\n @@ -225,16 +225,16 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, } else { char buffer[256]; - sprintf(buffer,"python%d%d.dll", + PyOS_snprintf(buffer, sizeof(buffer), "python%d%d.dll", PY_MAJOR_VERSION,PY_MINOR_VERSION); import_python = GetPythonImport(hDLL); if (import_python && strcasecmp(buffer,import_python)) { - sprintf(buffer, - "Module use of %.150s conflicts " - "with this version of Python.", - import_python); + PyOS_snprintf(buffer, sizeof(buffer), + "Module use of %.150s conflicts " + "with this version of Python.", + import_python); PyErr_SetString(PyExc_ImportError,buffer); FreeLibrary(hDLL); return NULL; @@ -251,14 +251,16 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, strchr(pathname, '/') == NULL) { /* Prefix bare filename with ".\" */ - sprintf(pathbuf, ".\\%-.13s", pathname); + PyOS_snprintf(pathbuf, sizeof(pathbuf), + ".\\%-.13s", pathname); pathname = pathbuf; } hDLL = LoadLibrary(pathname); if (hDLL < HINSTANCE_ERROR){ char errBuf[256]; - sprintf(errBuf, - "DLL load failed with error code %d", hDLL); + PyOS_snprintf(errBuf, sizeof(errBuf), + "DLL load failed with error code %d", + hDLL); PyErr_SetString(PyExc_ImportError, errBuf); return NULL; } diff --git a/Python/getversion.c b/Python/getversion.c index b0ef389..7af16fc 100644 --- a/Python/getversion.c +++ b/Python/getversion.c @@ -9,7 +9,7 @@ const char * Py_GetVersion(void) { static char version[250]; - sprintf(version, "%.80s (%.80s) %.80s", PY_VERSION, - Py_GetBuildInfo(), Py_GetCompiler()); + PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s", + PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler()); return version; } diff --git a/Python/pythonrun.c b/Python/pythonrun.c index f6217c3..628058b 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -933,7 +933,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) else PyFile_WriteString(filename, f); PyFile_WriteString("\", line ", f); - sprintf(buf, "%d", lineno); + PyOS_snprintf(buf, sizeof(buf), "%d", lineno); PyFile_WriteString(buf, f); PyFile_WriteString("\n", f); if (text != NULL) diff --git a/Python/strerror.c b/Python/strerror.c index b803b29..aeb7dd5 100644 --- a/Python/strerror.c +++ b/Python/strerror.c @@ -3,6 +3,7 @@ Author: Guido van Rossum, CWI Amsterdam, Oct. 1990, <guido@cwi.nl>. */ #include <stdio.h> +#include "Python.h" extern int sys_nerr; extern char *sys_errlist[]; @@ -13,7 +14,7 @@ strerror(int err) static char buf[20]; if (err >= 0 && err < sys_nerr) return sys_errlist[err]; - sprintf(buf, "Unknown errno %d", err); + PyOS_snprintf(buf, sizeof(buf), "Unknown errno %d", err); return buf; } diff --git a/Python/traceback.c b/Python/traceback.c index 6abde64..fee9d12 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -195,7 +195,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name) } } } - sprintf(linebuf, FMT, filename, lineno, name); + PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name); err = PyFile_WriteString(linebuf, f); if (xfp == NULL || err != 0) return err; |