diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-12-10 10:36:32 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-12-10 10:36:32 (GMT) |
commit | fd25634715d10d5693bcd6215f548fdd43058d41 (patch) | |
tree | 5a55a75b0adba7d3b2448ea9f20220af9d7ef0b3 /Include | |
parent | 9fa9a0d635b9fee1ba7b643869cb7b70e9809716 (diff) | |
download | cpython-fd25634715d10d5693bcd6215f548fdd43058d41.zip cpython-fd25634715d10d5693bcd6215f548fdd43058d41.tar.gz cpython-fd25634715d10d5693bcd6215f548fdd43058d41.tar.bz2 |
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.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/pymem.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Include/pymem.h b/Include/pymem.h index e2dfe0d..966c0f5 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -71,9 +71,9 @@ PyAPI_FUNC(void) PyMem_Free(void *); 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 |