[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.87,1.88
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-07-25 01:10:04
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11670 Modified Files: win32apimodule.cpp Log Message: Fix GetConsoleTitle to match the documented and observed behaviour when growing the buffer. Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** win32apimodule.cpp 30 Jun 2008 12:56:47 -0000 1.87 --- win32apimodule.cpp 25 Jul 2008 01:10:10 -0000 1.88 *************** *** 882,892 **** { TCHAR *title=NULL; ! DWORD chars_allocated=64, chars_returned; PyObject *ret=NULL; if (!PyArg_ParseTuple(args, ":GetConsoleTitle")) return NULL; ! // if buffer is too small, function still copies as much of title as will fit, ! // so loop until fewer characters returned than were allocated while (TRUE){ if (title!=NULL){ --- 882,896 ---- { TCHAR *title=NULL; ! DWORD chars_allocated=1024, chars_returned; PyObject *ret=NULL; if (!PyArg_ParseTuple(args, ":GetConsoleTitle")) return NULL; ! // We used to rely on that if buffer is too small, function still copies ! // as much of title as will fit, so loop until fewer characters returned ! // than were allocated. ! // Latest MSDN now says "If the buffer is not large enough to store ! // the title, the return value is zero and GetLastError returns ! // ERROR_SUCCESS." while (TRUE){ if (title!=NULL){ *************** *** 898,905 **** return PyErr_Format(PyExc_MemoryError, "GetConsoleTitle: unable to allocate %d bytes", chars_allocated*sizeof(TCHAR)); chars_returned=GetConsoleTitle(title, chars_allocated); ! if (chars_returned==0){ PyWin_SetAPIError("GetConsoleTitle"); break; ! } if ((chars_returned+1)<chars_allocated){ // returned length does *not* includes the NULL terminator ret=PyWinObject_FromTCHAR(title); --- 902,909 ---- return PyErr_Format(PyExc_MemoryError, "GetConsoleTitle: unable to allocate %d bytes", chars_allocated*sizeof(TCHAR)); chars_returned=GetConsoleTitle(title, chars_allocated); ! if (chars_returned==0 && GetLastError() != ERROR_SUCCESS){ PyWin_SetAPIError("GetConsoleTitle"); break; ! } if ((chars_returned+1)<chars_allocated){ // returned length does *not* includes the NULL terminator ret=PyWinObject_FromTCHAR(title); |