[Python-checkins] CVS: python/dist/src/Python sysmodule.c,2.96,2.97
M.-A. Lemburg
mal@lemburg.com
Sun, 02 Dec 2001 11:18:44 +0100
Tim Peters wrote:
>
> Update of /cvsroot/python/python/dist/src/Python
> In directory usw-pr-cvs1:/tmp/cvs-serv578/python/Python
>
> Modified Files:
> sysmodule.c
> Log Message:
> mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
> ends. Also, when there is trouble, ensure the buffer has a traiing
> 0 byte.
>
> Index: sysmodule.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
> retrieving revision 2.96
> retrieving revision 2.97
> diff -C2 -d -r2.96 -r2.97
> *** sysmodule.c 2001/11/28 21:44:53 2.96
> --- sysmodule.c 2001/12/02 08:29:16 2.97
> ***************
> *** 1024,1034 ****
> else {
> char buffer[1001];
> ! int written = PyOS_vsnprintf(buffer, sizeof(buffer),
> ! format, va);
> if (PyFile_WriteString(buffer, file) != 0) {
> PyErr_Clear();
> fputs(buffer, fp);
> }
> ! if (written == -1 || written > sizeof(buffer)) {
> const char *truncated = "... truncated";
> if (PyFile_WriteString(truncated, file) != 0) {
> --- 1024,1041 ----
> else {
> char buffer[1001];
> ! const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
> ! format, va);
> ! const int trouble = written < 0 || written >= sizeof(buffer);
> ! if (trouble) {
> ! /* Ensure there's a trailing null byte -- MS
> ! vsnprintf fills the buffer to the very end
> ! if it's not big enough. */
> ! buffer[sizeof(buffer) - 1] = '\0';
> ! }
Wouldn't it be bette to put this code into PyOS_vsnprintf()
for both cases (snprintf available/not available) ?
--
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/