[Python-checkins] r84153 - python/branches/py3k/PC/winreg.c

brian.curtin python-checkins at python.org
Tue Aug 17 22:08:40 CEST 2010


Author: brian.curtin
Date: Tue Aug 17 22:08:40 2010
New Revision: 84153

Log:
Properly downcast from size_t/Py_ssize_t in a few places.


Modified:
   python/branches/py3k/PC/winreg.c

Modified: python/branches/py3k/PC/winreg.c
==============================================================================
--- python/branches/py3k/PC/winreg.c	(original)
+++ python/branches/py3k/PC/winreg.c	Tue Aug 17 22:08:40 2010
@@ -765,8 +765,9 @@
             else {
                 if (!PyUnicode_Check(value))
                     return FALSE;
-
-                *retDataSize = 2 + PyUnicode_GET_DATA_SIZE(value);
+                *retDataSize = Py_SAFE_DOWNCAST(
+                                   2 + PyUnicode_GET_DATA_SIZE(value),
+                                   size_t, DWORD);
             }
             *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize);
             if (*retDataBuf==NULL){
@@ -798,7 +799,8 @@
                     t = PyList_GET_ITEM(value, j);
                     if (!PyUnicode_Check(t))
                         return FALSE;
-                    size += 2 + PyUnicode_GET_DATA_SIZE(t);
+                    size += Py_SAFE_DOWNCAST(2 + PyUnicode_GET_DATA_SIZE(t),
+                                             size_t, DWORD);
                 }
 
                 *retDataSize = size + 2;
@@ -848,7 +850,7 @@
                     PyErr_NoMemory();
                     return FALSE;
                 }
-                *retDataSize = view.len;
+                *retDataSize = Py_SAFE_DOWNCAST(view.len, Py_ssize_t, DWORD);
                 memcpy(*retDataBuf, view.buf, view.len);
                 PyBuffer_Release(&view);
             }


More information about the Python-checkins mailing list