aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-06-18 00:47:36 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-06-18 00:47:36 +0000
commit9c74b14fe9b6dddc9d41dd37f431f174350004d4 (patch)
tree3d30d794259f55f5021f5e8036447523d0e1eea3 /Include/pymem.h
parentMerged revisions 64360-64361 via svnmerge from (diff)
downloadcpython-9c74b14fe9b6dddc9d41dd37f431f174350004d4.tar.gz
cpython-9c74b14fe9b6dddc9d41dd37f431f174350004d4.tar.bz2
cpython-9c74b14fe9b6dddc9d41dd37f431f174350004d4.zip
Merged revisions 64114 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r64114 | gregory.p.smith | 2008-06-11 09:41:16 +0200 (mer., 11 juin 2008) | 6 lines Merge in release25-maint r60793: Added checks for integer overflows, contributed by Google. Some are only available if asserts are left in the code, in cases where they can't be triggered from Python code. ........
Diffstat (limited to 'Include/pymem.h')
-rw-r--r--Include/pymem.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/Include/pymem.h b/Include/pymem.h
index 7f74f3701b0..f9acb55f745 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -85,14 +85,18 @@ PyAPI_FUNC(void) PyMem_Free(void *);
*/
#define PyMem_New(type, n) \
- ( (type *) PyMem_Malloc((n) * sizeof(type)) )
+ ( assert((n) <= PY_SIZE_MAX / sizeof(type)) , \
+ ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
#define PyMem_NEW(type, n) \
- ( (type *) PyMem_MALLOC((n) * sizeof(type)) )
+ ( assert((n) <= PY_SIZE_MAX / sizeof(type)) , \
+ ( (type *) PyMem_MALLOC((n) * sizeof(type)) ) )
#define PyMem_Resize(p, type, n) \
- ( (p) = (type *) PyMem_Realloc((p), (n) * sizeof(type)) )
+ ( assert((n) <= PY_SIZE_MAX / sizeof(type)) , \
+ ( (p) = (type *) PyMem_Realloc((p), (n) * sizeof(type)) ) )
#define PyMem_RESIZE(p, type, n) \
- ( (p) = (type *) PyMem_REALLOC((p), (n) * sizeof(type)) )
+ ( assert((n) <= PY_SIZE_MAX / sizeof(type)) , \
+ ( (p) = (type *) PyMem_REALLOC((p), (n) * sizeof(type)) ) )
/* PyMem{Del,DEL} are left over from ancient days, and shouldn't be used
* anymore. They're just confusing aliases for PyMem_{Free,FREE} now.