Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75cdad5

Browse files
committed
More sprintf -> PyOS_snprintf.
1 parent 179c48c commit 75cdad5

5 files changed

Lines changed: 14 additions & 9 deletions

File tree

Modules/almodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,8 @@ al_GetParams(PyObject *self, PyObject *args)
15191519
for (i = 0; i < npvs; i++) {
15201520
if (pvs[i].sizeOut < 0) {
15211521
char buf[32];
1522-
sprintf(buf, "problem with param %d", i);
1522+
PyOS_snprintf(buf, sizeof(buf),
1523+
"problem with param %d", i);
15231524
PyErr_SetString(ErrorObject, buf);
15241525
goto error;
15251526
}

Modules/posixmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ _PyPopenCreateProcess(char *cmdstring,
25552555
x = i + strlen(s3) + strlen(cmdstring) + 1;
25562556
s2 = (char *)_alloca(x);
25572557
ZeroMemory(s2, x);
2558-
sprintf(s2, "%s%s%s", s1, s3, cmdstring);
2558+
PyOS_snprintf(s2, x, "%s%s%s", s1, s3, cmdstring);
25592559
}
25602560
else {
25612561
/*
@@ -2608,8 +2608,8 @@ _PyPopenCreateProcess(char *cmdstring,
26082608

26092609
s2 = (char *)_alloca(x);
26102610
ZeroMemory(s2, x);
2611-
sprintf(
2612-
s2,
2611+
PyOS_snprintf(
2612+
s2, x,
26132613
"%s \"%s%s%s\"",
26142614
modulepath,
26152615
s1,

Modules/socketmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,8 @@ OS2init(void)
30893089
return 1; /* Indicate Success */
30903090
}
30913091

3092-
sprintf(reason, "OS/2 TCP/IP Error# %d", sock_errno());
3092+
PyOS_snprintf(reason, sizeof(reason),
3093+
"OS/2 TCP/IP Error# %d", sock_errno());
30933094
PyErr_SetString(PyExc_ImportError, reason);
30943095

30953096
return 0; /* Indicate Failure */

Modules/stropmodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@ strop_atoi(PyObject *self, PyObject *args)
778778
return NULL;
779779
}
780780
else if (errno != 0) {
781-
sprintf(buffer, "atoi() literal too large: %.200s", s);
781+
PyOS_snprintf(buffer, sizeof(buffer),
782+
"atoi() literal too large: %.200s", s);
782783
PyErr_SetString(PyExc_ValueError, buffer);
783784
return NULL;
784785
}
@@ -828,7 +829,8 @@ strop_atol(PyObject *self, PyObject *args)
828829
while (*end && isspace(Py_CHARMASK(*end)))
829830
end++;
830831
if (*end != '\0') {
831-
sprintf(buffer, "invalid literal for atol(): %.200s", s);
832+
PyOS_snprintf(buffer, sizeof(buffer),
833+
"invalid literal for atol(): %.200s", s);
832834
PyErr_SetString(PyExc_ValueError, buffer);
833835
Py_DECREF(x);
834836
return NULL;

Python/thread_beos.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ long PyThread_start_new_thread( void (*func)(void *), void *arg )
123123

124124
/* We are so very thread-safe... */
125125
this_thread = atomic_add( &thread_count, 1 );
126-
sprintf( name, "python thread (%d)", this_thread );
126+
PyOS_snprintf(name, sizeof(name),
127+
"python thread (%d)", this_thread );
127128

128129
tid = spawn_thread( (thread_func)func, name,
129130
B_NORMAL_PRIORITY, arg );
@@ -222,7 +223,7 @@ PyThread_type_lock PyThread_allocate_lock( void )
222223
}
223224

224225
this_lock = atomic_add( &lock_count, 1 );
225-
sprintf( name, "python lock (%d)", this_lock );
226+
PyOS_snprintf(name, sizeof(name), "python lock (%d)", this_lock);
226227

227228
retval = benaphore_create( name, lock );
228229
if( retval != EOK ) {

0 commit comments

Comments
 (0)