Add (size_t) casts to MALLOCX_ALIGN().
Add (size_t) casts to MALLOCX_ALIGN() macros so that passing the integer constant 0x80000000 does not cause a compiler warning about invalid shift amount. This resolves #354.
This commit is contained in:
parent
ca18f2834e
commit
824b947be0
@ -13,11 +13,11 @@
|
||||
|
||||
# define MALLOCX_LG_ALIGN(la) ((int)(la))
|
||||
# if LG_SIZEOF_PTR == 2
|
||||
# define MALLOCX_ALIGN(a) ((int)(ffs(a)-1))
|
||||
# define MALLOCX_ALIGN(a) ((int)(ffs((int)(a))-1))
|
||||
# else
|
||||
# define MALLOCX_ALIGN(a) \
|
||||
((int)(((a) < (size_t)INT_MAX) ? ffs((int)(a))-1 : \
|
||||
ffs((int)((a)>>32))+31))
|
||||
((int)(((size_t)(a) < (size_t)INT_MAX) ? ffs((int)(a))-1 : \
|
||||
ffs((int)(((size_t)(a))>>32))+31))
|
||||
# endif
|
||||
# define MALLOCX_ZERO ((int)0x40)
|
||||
/*
|
||||
@ -29,7 +29,7 @@
|
||||
/*
|
||||
* Bias arena index bits so that 0 encodes "use an automatically chosen arena".
|
||||
*/
|
||||
# define MALLOCX_ARENA(a) ((int)(((a)+1) << 20))
|
||||
# define MALLOCX_ARENA(a) ((((int)(a))+1) << 20)
|
||||
|
||||
#if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW)
|
||||
# define JEMALLOC_CXX_THROW throw()
|
||||
|
@ -69,18 +69,14 @@ TEST_END
|
||||
|
||||
TEST_BEGIN(test_oom)
|
||||
{
|
||||
size_t hugemax, size, alignment;
|
||||
|
||||
hugemax = get_huge_size(get_nhuge()-1);
|
||||
|
||||
/*
|
||||
* It should be impossible to allocate two objects that each consume
|
||||
* more than half the virtual address space.
|
||||
*/
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = mallocx(hugemax, 0);
|
||||
size_t hugemax = get_huge_size(get_nhuge()-1);
|
||||
void *p = mallocx(hugemax, 0);
|
||||
if (p != NULL) {
|
||||
assert_ptr_null(mallocx(hugemax, 0),
|
||||
"Expected OOM for mallocx(size=%#zx, 0)", hugemax);
|
||||
@ -89,15 +85,16 @@ TEST_BEGIN(test_oom)
|
||||
}
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
size = ZU(0x8000000000000000);
|
||||
alignment = ZU(0x8000000000000000);
|
||||
assert_ptr_null(mallocx(0x8000000000000000ULL,
|
||||
MALLOCX_ALIGN(0x8000000000000000ULL)),
|
||||
"Expected OOM for mallocx()");
|
||||
assert_ptr_null(mallocx(0x8000000000000000ULL,
|
||||
MALLOCX_ALIGN(0x80000000)),
|
||||
"Expected OOM for mallocx()");
|
||||
#else
|
||||
size = ZU(0x80000000);
|
||||
alignment = ZU(0x80000000);
|
||||
assert_ptr_null(mallocx(0x80000000UL, MALLOCX_ALIGN(0x80000000UL)),
|
||||
"Expected OOM for mallocx()");
|
||||
#endif
|
||||
assert_ptr_null(mallocx(size, MALLOCX_ALIGN(alignment)),
|
||||
"Expected OOM for mallocx(size=%#zx, MALLOCX_ALIGN(%#zx)", size,
|
||||
alignment);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user