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;
}
{
char funcname[258];
- sprintf(funcname, "init%.200s", shortname);
+ PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
return dl_loadmod(Py_GetProgramName(), pathname, funcname);
}
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);
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;
}
** 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;
}
dl_funcptr p = NULL;
char funcname[258];
- sprintf(funcname, "_init%.200s", shortname);
+ PyOS_snprintf(funcname, sizeof(funcname), "_init%.200s", shortname);
#ifdef USE_RLD
{
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 */
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;
dl_funcptr p;
char funcname[258], *import_python;
- sprintf(funcname, "init%.200s", shortname);
+ PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
#ifdef MS_WIN32
{
/* 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
} 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;
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;
}
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;
}
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)
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[];
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;
}
}
}
}
- 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;
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;
}