Skip to content

Commit ade334c

Browse files
committed
Convert ones using direct allocation
1 parent 61eee4d commit ade334c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,11 +3360,12 @@ static PPROC FindAddress(void *handle, const char *name, PyObject *type)
33603360
funcname -> _funcname@<n>
33613361
where n is 0, 4, 8, 12, ..., 128
33623362
*/
3363-
mangled_name = alloca(strlen(name) + 1 + 1 + 1 + 3); /* \0 _ @ %d */
3363+
int toalloc = strlen(name) + 1 + 1 + 1 + 3; /* \0 _ @ %d */
3364+
mangled_name = alloca(toalloc);
33643365
if (!mangled_name)
33653366
return NULL;
33663367
for (i = 0; i < 32; ++i) {
3367-
sprintf(mangled_name, "_%s@%d", name, i*4);
3368+
PyOS_snprintf(mangled_name, toalloc, "_%s@%d", name, i*4);
33683369
Py_BEGIN_ALLOW_THREADS
33693370
address = (PPROC)GetProcAddress(handle, mangled_name);
33703371
Py_END_ALLOW_THREADS

Modules/_ctypes/stgdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
612612
PyErr_NoMemory();
613613
return -1;
614614
}
615-
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
615+
PyOS_snprintf(buf, len + 2 + 1, "%s:%s:", fieldfmt, fieldname);
616616

617617
ptr = stgdict->format;
618618
if (dict->shape != NULL) {

Programs/_freeze_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static PyObject *
124124
compile_and_marshal(const char *name, const char *text)
125125
{
126126
char *filename = (char *) malloc(strlen(name) + 10);
127-
sprintf(filename, "<frozen %s>", name);
127+
PyOS_snprintf(filename, strlen(name) + 10, "<frozen %s>", name);
128128
PyObject *code = Py_CompileStringExFlags(text, filename,
129129
Py_file_input, NULL, 0);
130130
free(filename);

0 commit comments

Comments
 (0)