]> granicus.if.org Git - python/commitdiff
Use PyOS_snprintf instead of sprintf.
authorJeremy Hylton <jeremy@alum.mit.edu>
Wed, 28 Nov 2001 20:42:20 +0000 (20:42 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Wed, 28 Nov 2001 20:42:20 +0000 (20:42 +0000)
13 files changed:
Python/bltinmodule.c
Python/dynload_dl.c
Python/dynload_hpux.c
Python/dynload_mac.c
Python/dynload_next.c
Python/dynload_os2.c
Python/dynload_shlib.c
Python/dynload_win.c
Python/getversion.c
Python/pythonrun.c
Python/strerror.c
Python/traceback.c
RISCOS/Python/dynload_riscos.c

index b6e44608133d87a2fa89d31c541b5711aa16c9f4..8e4ca2ec5a1d908eb9a3380adb53795f3a2e049c 100644 (file)
@@ -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;
                }
index 5a62d6f9aa176c8a68eb82f43ed85ae035d063e3..4675a6722ac159efa1792dc4ca5c76ded7284663 100644 (file)
@@ -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);
 }
index e435cd895c6ef9214da4106e298e45a99474fae1..cbdb35a240ad1dc1ad311692c1aa2442128596b3 100644 (file)
@@ -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);
index c8c9646bd89c1a4a626adddc683a849c6db70ae8..bb5f4fb6c50dd7ff81ff1202c8eae1acb93897a6 100644 (file)
@@ -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;
        }
index 2b34315adf0000eda1fb1f8074c56e68d14cbc49..671b26f2357e3bce8fd8d07bcd09e3231f9f8a63 100644 (file)
@@ -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
        {
index a3eb46835f65531faabc0368e6be66a8953c97d8..d660e27501ae5c39caac4c94ae631cb7a07debff 100644 (file)
@@ -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 */
index 569a6f52ce837df975174280199d5df4049d45cc..e8a04ce500a00771416db7a7d4518f793af2ae58 100644 (file)
@@ -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;
index 155a9d64325c48d150194c16f5a8c481a6e39d48..9062cf3b8815e024e39ce11c1a3c19fdcd792e53 100644 (file)
@@ -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;
                }
index b0ef3896ef40153bb958be339b5311583338bfb2..7af16fc8109e973ee6e23583ee484582cf285e7c 100644 (file)
@@ -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;
 }
index f6217c3da64158ea156d349c487cb1292f35fedc..628058b8b8828533167ea046a726c31788f08f2a 100644 (file)
@@ -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)
index b803b29835e00af826a6c85fd359e237a34ca910..aeb7dd57341979395f2c52c14804e8154dc8c7f5 100644 (file)
@@ -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;
 }
 
index 6abde64de6dd312ca5d9f7399884e7c34527ea03..fee9d12a00e482e4e4d073ee5fe71c325388be44 100644 (file)
@@ -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;
index 6965647062621b4d2f5d81726f0d1b31f015b0fc..6b87f2df137c27f533b9cb5445b678188454e3b9 100644 (file)
@@ -55,10 +55,9 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
        void (*init_function)(void);
 
        err = dlk_load_no_init(pathname, &init_function);
-       if (err)
-       {
-         sprintf(errstr, "dlk failure %d", err);
-         PyErr_SetString(PyExc_ImportError, errstr);
+       if (err) {
+           PyOS_snprintf(errstr, sizeof(errstr), "dlk failure %d", err);
+           PyErr_SetString(PyExc_ImportError, errstr);
        }
        return init_function;
 }