[Python-checkins] r76740 - python/trunk/Include/pymem.h
mark.dickinson
python-checkins at python.org
Thu Dec 10 11:36:32 CET 2009
Author: mark.dickinson
Date: Thu Dec 10 11:36:32 2009
New Revision: 76740
Log:
Replace the size check for PyMem_MALLOC and PyMem_REALLOC with an almost
equivalent[*] check that doesn't produce compiler warnings about a 'x < 0'
check on an unsigned type.
[*] it's equivalent for inputs of type size_t or Py_ssize_t, or any smaller
unsigned or signed integer type.
Modified:
python/trunk/Include/pymem.h
Modified: python/trunk/Include/pymem.h
==============================================================================
--- python/trunk/Include/pymem.h (original)
+++ python/trunk/Include/pymem.h Thu Dec 10 11:36:32 2009
@@ -71,9 +71,9 @@
pymalloc. To solve these problems, allocate an extra byte. */
/* Returns NULL to indicate error if a negative size or size larger than
Py_ssize_t can represent is supplied. Helps prevents security holes. */
-#define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \
+#define PyMem_MALLOC(n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \
: malloc((n) ? (n) : 1))
-#define PyMem_REALLOC(p, n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \
+#define PyMem_REALLOC(p, n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \
: realloc((p), (n) ? (n) : 1))
#define PyMem_FREE free
More information about the Python-checkins
mailing list