@@ -159,7 +159,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
159159 dl_funcptr p ;
160160 char funcname [258 ], * import_python ;
161161
162- sprintf (funcname , "init%.200s" , shortname );
162+ PyOS_snprintf (funcname , sizeof ( funcname ) , "init%.200s" , shortname );
163163
164164#ifdef MS_WIN32
165165 {
@@ -201,9 +201,9 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
201201 /* Problem: could not get the error message.
202202 This should not happen if called correctly. */
203203 if (theLength == 0 ) {
204- sprintf (errBuf ,
205- "DLL load failed with error code %d" ,
206- errorCode );
204+ PyOS_snprintf (errBuf , sizeof ( errBuf ) ,
205+ "DLL load failed with error code %d" ,
206+ errorCode );
207207 } else {
208208 size_t len ;
209209 /* For some reason a \r\n
@@ -225,16 +225,16 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
225225 } else {
226226 char buffer [256 ];
227227
228- sprintf (buffer ,"python%d%d.dll" ,
228+ PyOS_snprintf (buffer , sizeof ( buffer ), "python%d%d.dll" ,
229229 PY_MAJOR_VERSION ,PY_MINOR_VERSION );
230230 import_python = GetPythonImport (hDLL );
231231
232232 if (import_python &&
233233 strcasecmp (buffer ,import_python )) {
234- sprintf (buffer ,
235- "Module use of %.150s conflicts "
236- "with this version of Python." ,
237- import_python );
234+ PyOS_snprintf (buffer , sizeof ( buffer ) ,
235+ "Module use of %.150s conflicts "
236+ "with this version of Python." ,
237+ import_python );
238238 PyErr_SetString (PyExc_ImportError ,buffer );
239239 FreeLibrary (hDLL );
240240 return NULL ;
@@ -251,14 +251,16 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
251251 strchr (pathname , '/' ) == NULL )
252252 {
253253 /* Prefix bare filename with ".\" */
254- sprintf (pathbuf , ".\\%-.13s" , pathname );
254+ PyOS_snprintf (pathbuf , sizeof (pathbuf ),
255+ ".\\%-.13s" , pathname );
255256 pathname = pathbuf ;
256257 }
257258 hDLL = LoadLibrary (pathname );
258259 if (hDLL < HINSTANCE_ERROR ){
259260 char errBuf [256 ];
260- sprintf (errBuf ,
261- "DLL load failed with error code %d" , hDLL );
261+ PyOS_snprintf (errBuf , sizeof (errBuf ),
262+ "DLL load failed with error code %d" ,
263+ hDLL );
262264 PyErr_SetString (PyExc_ImportError , errBuf );
263265 return NULL ;
264266 }
0 commit comments