diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-20 18:56:47 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-20 18:56:47 (GMT) |
commit | ca8aa4acf6755dd012706e1e38fb737ae83ab5c6 (patch) | |
tree | 310b20a536a99dd80657e2d22e07bb1466d0a895 /Objects/obmalloc.c | |
parent | 1c47222a256f2977dcbb36c05dce7a5ae8e6ae06 (diff) | |
download | cpython-ca8aa4acf6755dd012706e1e38fb737ae83ab5c6.zip cpython-ca8aa4acf6755dd012706e1e38fb737ae83ab5c6.tar.gz cpython-ca8aa4acf6755dd012706e1e38fb737ae83ab5c6.tar.bz2 |
Issue #15144: Fix possible integer overflow when handling pointers as integer values, by using Py_uintptr_t instead of size_t.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r-- | Objects/obmalloc.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 9254821..6225ebb 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -138,7 +138,6 @@ static int running_on_valgrind = -1; */ #define ALIGNMENT 8 /* must be 2^N */ #define ALIGNMENT_SHIFT 3 -#define ALIGNMENT_MASK (ALIGNMENT - 1) /* Return the number of bytes in size class I, as a uint. */ #define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT) @@ -314,14 +313,12 @@ struct arena_object { struct arena_object* prevarena; }; -#undef ROUNDUP -#define ROUNDUP(x) (((x) + ALIGNMENT_MASK) & ~ALIGNMENT_MASK) -#define POOL_OVERHEAD ROUNDUP(sizeof(struct pool_header)) +#define POOL_OVERHEAD _Py_SIZE_ROUND_UP(sizeof(struct pool_header), ALIGNMENT) #define DUMMY_SIZE_IDX 0xffff /* size class of newly cached pools */ /* Round pointer P down to the closest pool-aligned address <= P, as a poolp */ -#define POOL_ADDR(P) ((poolp)((uptr)(P) & ~(uptr)POOL_SIZE_MASK)) +#define POOL_ADDR(P) ((poolp)_Py_ALIGN_DOWN((P), POOL_SIZE)) /* Return total number of blocks in pool of size index I, as a uint. */ #define NUMBLOCKS(I) ((uint)(POOL_SIZE - POOL_OVERHEAD) / INDEX2SIZE(I)) |