@@ -392,9 +392,9 @@ _ctypes_alloc_format_string_with_shape(int ndim, const Py_ssize_t *shape,
392
392
strcat (new_prefix , "(" );
393
393
for (k = 0 ; k < ndim ; ++ k ) {
394
394
if (k < ndim - 1 ) {
395
- sprintf (buf , "%zd," , shape [k ]);
395
+ snprintf (buf , sizeof ( buf ) , "%zd," , shape [k ]);
396
396
} else {
397
- sprintf (buf , "%zd)" , shape [k ]);
397
+ snprintf (buf , sizeof ( buf ) , "%zd)" , shape [k ]);
398
398
}
399
399
strcat (new_prefix , buf );
400
400
}
@@ -2639,7 +2639,8 @@ unique_key(CDataObject *target, Py_ssize_t index)
2639
2639
size_t bytes_left ;
2640
2640
2641
2641
Py_BUILD_ASSERT (sizeof (string ) - 1 > sizeof (Py_ssize_t ) * 2 );
2642
- cp += sprintf (cp , "%x" , Py_SAFE_DOWNCAST (index , Py_ssize_t , int ));
2642
+ cp += snprintf (cp , sizeof (cp ), "%x" ,
2643
+ Py_SAFE_DOWNCAST (index , Py_ssize_t , int ));
2643
2644
while (target -> b_base ) {
2644
2645
bytes_left = sizeof (string ) - (cp - string ) - 1 ;
2645
2646
/* Hex format needs 2 characters per byte */
@@ -2648,7 +2649,8 @@ unique_key(CDataObject *target, Py_ssize_t index)
2648
2649
"ctypes object structure too deep" );
2649
2650
return NULL ;
2650
2651
}
2651
- cp += sprintf (cp , ":%x" , Py_SAFE_DOWNCAST (target -> b_index , Py_ssize_t , int ));
2652
+ cp += snprintf (cp , sizeof (cp ), ":%x" ,
2653
+ Py_SAFE_DOWNCAST (target -> b_index , Py_ssize_t , int ));
2652
2654
target = target -> b_base ;
2653
2655
}
2654
2656
return PyUnicode_FromStringAndSize (string , cp - string );
@@ -3364,7 +3366,7 @@ static PPROC FindAddress(void *handle, const char *name, PyObject *type)
3364
3366
if (!mangled_name )
3365
3367
return NULL ;
3366
3368
for (i = 0 ; i < 32 ; ++ i ) {
3367
- sprintf (mangled_name , "_%s@%d" , name , i * 4 );
3369
+ snprintf (mangled_name , sizeof ( mangled_name ) , "_%s@%d" , name , i * 4 );
3368
3370
Py_BEGIN_ALLOW_THREADS
3369
3371
address = (PPROC )GetProcAddress (handle , mangled_name );
3370
3372
Py_END_ALLOW_THREADS
@@ -4851,10 +4853,10 @@ PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length)
4851
4853
return NULL ;
4852
4854
}
4853
4855
#ifdef MS_WIN64
4854
- sprintf (name , "%.200s_Array_%Id" ,
4856
+ snprintf (name , sizeof ( name ) , "%.200s_Array_%Id" ,
4855
4857
((PyTypeObject * )itemtype )-> tp_name , length );
4856
4858
#else
4857
- sprintf (name , "%.200s_Array_%ld" ,
4859
+ snprintf (name , sizeof ( name ) , "%.200s_Array_%ld" ,
4858
4860
((PyTypeObject * )itemtype )-> tp_name , (long )length );
4859
4861
#endif
4860
4862
0 commit comments