[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.212,2.213
Tim Peters
tim_one@users.sourceforge.net
Mon, 03 Dec 2001 12:41:02 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv6722/python/Modules
Modified Files:
posixmodule.c
Log Message:
posix_execve(), posix_spawnve(), posix_putenv():
sprintf -> PyOS_snprintf. This is the last of this
stuff I intend to do.
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.212
retrieving revision 2.213
diff -C2 -d -r2.212 -r2.213
*** posixmodule.c 2001/11/28 22:07:30 2.212
--- posixmodule.c 2001/12/03 20:41:00 2.213
***************
*** 1611,1614 ****
--- 1611,1615 ----
for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
+ size_t len;
key = PyList_GetItem(keys, pos);
***************
*** 1627,1636 ****
if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif
! p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2);
if (p == NULL) {
PyErr_NoMemory();
goto fail_2;
}
! sprintf(p, "%s=%s", k, v);
envlist[envc++] = p;
#if defined(PYOS_OS2)
--- 1628,1638 ----
if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif
! len = PyString_Size(key) + PyString_Size(val) + 2;
! p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
goto fail_2;
}
! PyOS_snprintf(p, len, "%s=%s", k, v);
envlist[envc++] = p;
#if defined(PYOS_OS2)
***************
*** 1804,1807 ****
--- 1806,1810 ----
for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
+ size_t len;
key = PyList_GetItem(keys, pos);
***************
*** 1815,1824 ****
goto fail_2;
}
! p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2);
if (p == NULL) {
PyErr_NoMemory();
goto fail_2;
}
! sprintf(p, "%s=%s", k, v);
envlist[envc++] = p;
}
--- 1818,1828 ----
goto fail_2;
}
! len = PyString_Size(key) + PyString_Size(val) + 2;
! p = PyMem_NEW(char, len);
if (p == NULL) {
PyErr_NoMemory();
goto fail_2;
}
! PyOS_snprintf(p, len, "%s=%s", k, v);
envlist[envc++] = p;
}
***************
*** 4031,4034 ****
--- 4035,4039 ----
char *new;
PyObject *newstr;
+ size_t len;
if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2))
***************
*** 4059,4067 ****
/* XXX This can leak memory -- not easy to fix :-( */
! newstr = PyString_FromStringAndSize(NULL, strlen(s1) + strlen(s2) + 2);
if (newstr == NULL)
return PyErr_NoMemory();
new = PyString_AS_STRING(newstr);
! (void) sprintf(new, "%s=%s", s1, s2);
if (putenv(new)) {
posix_error();
--- 4064,4075 ----
/* XXX This can leak memory -- not easy to fix :-( */
! len = strlen(s1) + strlen(s2) + 2;
! /* len includes space for a trailing \0; the size arg to
! PyString_FromStringAndSize does not count that */
! newstr = PyString_FromStringAndSize(NULL, (int)len - 1);
if (newstr == NULL)
return PyErr_NoMemory();
new = PyString_AS_STRING(newstr);
! PyOS_snprintf(new, len, "%s=%s", s1, s2);
if (putenv(new)) {
posix_error();