]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Properly downcast from size_t/Py_ssize_t in a few places.
authorBrian Curtin <brian.curtin@gmail.com>
Tue, 17 Aug 2010 20:08:40 +0000 (20:08 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Tue, 17 Aug 2010 20:08:40 +0000 (20:08 +0000)
PC/winreg.c

index eacb4c2723ebe20c936ce8ea3c82778f08edd9e1..390a9ce2a7810890c94b9e95aa8f506dfa78d4c9 100644 (file)
@@ -765,8 +765,9 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
             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 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
                     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 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
                     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);
             }