mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Use PyOS_snprintf instead of sprintf.
This commit is contained in:
		
							parent
							
								
									ef58b31991
								
							
						
					
					
						commit
						518ab1c02a
					
				
					 13 changed files with 45 additions and 39 deletions
				
			
		|  | @ -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; | ||||
| 		} | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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; | ||||
| 	} | ||||
|  |  | |||
|  | @ -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 | ||||
| 	{ | ||||
|  |  | |||
|  | @ -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 */ | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
| 		} | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeremy Hylton
						Jeremy Hylton