示例#1
0
TEST_END

TEST_BEGIN(test_overflow) {
	size_t largemax;
	void *p;

	largemax = get_large_size(get_nlarge()-1);

	p = mallocx(1, 0);
	assert_ptr_not_null(p, "Unexpected mallocx() failure");

	assert_ptr_null(rallocx(p, largemax+1, 0),
	    "Expected OOM for rallocx(p, size=%#zx, 0)", largemax+1);

	assert_ptr_null(rallocx(p, ZU(PTRDIFF_MAX)+1, 0),
	    "Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);

	assert_ptr_null(rallocx(p, SIZE_T_MAX, 0),
	    "Expected OOM for rallocx(p, size=%#zx, 0)", SIZE_T_MAX);

	assert_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)),
	    "Expected OOM for rallocx(p, size=1, MALLOCX_ALIGN(%#zx))",
	    ZU(PTRDIFF_MAX)+1);

	dallocx(p, 0);
}
示例#2
0
TEST_END

TEST_BEGIN(test_extra_huge)
{
	int flags = MALLOCX_ARENA(arena_ind());
	size_t largemax, huge1, huge2, huge3, hugemax;
	void *p;

	/* Get size classes. */
	largemax = get_large_size(get_nlarge()-1);
	huge1 = get_huge_size(1);
	huge2 = get_huge_size(2);
	huge3 = get_huge_size(3);
	hugemax = get_huge_size(get_nhuge()-1);

	p = mallocx(huge3, flags);
	assert_ptr_not_null(p, "Unexpected mallocx() error");

	assert_zu_eq(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	/* Test size decrease with zero extra. */
	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	assert_zu_ge(xallocx(p, largemax, 0, flags), huge1,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	/* Test size decrease with non-zero extra. */
	assert_zu_eq(xallocx(p, huge1, huge3 - huge1, flags), huge3,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, huge2, huge3 - huge2, flags), huge3,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, huge1, huge2 - huge1, flags), huge2,
	    "Unexpected xallocx() behavior");
	assert_zu_ge(xallocx(p, largemax, huge1 - largemax, flags), huge1,
	    "Unexpected xallocx() behavior");

	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	/* Test size increase with zero extra. */
	assert_zu_le(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	assert_zu_le(xallocx(p, hugemax+1, 0, flags), huge3,
	    "Unexpected xallocx() behavior");

	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	/* Test size increase with non-zero extra. */
	assert_zu_le(xallocx(p, huge1, SIZE_T_MAX - huge1, flags), hugemax,
	    "Unexpected xallocx() behavior");

	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	/* Test size increase with non-zero extra. */
	assert_zu_le(xallocx(p, huge1, huge3 - huge1, flags), huge3,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	/* Test size+extra overflow. */
	assert_zu_le(xallocx(p, huge3, hugemax - huge3 + 1, flags), hugemax,
	    "Unexpected xallocx() behavior");

	dallocx(p, flags);
}
示例#3
0
TEST_END

TEST_BEGIN(test_extra_large)
{
	int flags = MALLOCX_ARENA(arena_ind());
	size_t smallmax, large0, large1, large2, huge0, hugemax;
	void *p;

	/* Get size classes. */
	smallmax = get_small_size(get_nsmall()-1);
	large0 = get_large_size(0);
	large1 = get_large_size(1);
	large2 = get_large_size(2);
	huge0 = get_huge_size(0);
	hugemax = get_huge_size(get_nhuge()-1);

	p = mallocx(large2, flags);
	assert_ptr_not_null(p, "Unexpected mallocx() error");

	assert_zu_eq(xallocx(p, large2, 0, flags), large2,
	    "Unexpected xallocx() behavior");
	/* Test size decrease with zero extra. */
	assert_zu_eq(xallocx(p, large0, 0, flags), large0,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, smallmax, 0, flags), large0,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, large2, 0, flags), large2,
	    "Unexpected xallocx() behavior");
	/* Test size decrease with non-zero extra. */
	assert_zu_eq(xallocx(p, large0, large2 - large0, flags), large2,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, large1, large2 - large1, flags), large2,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, large0, large1 - large0, flags), large1,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, smallmax, large0 - smallmax, flags), large0,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, large0, 0, flags), large0,
	    "Unexpected xallocx() behavior");
	/* Test size increase with zero extra. */
	assert_zu_eq(xallocx(p, large2, 0, flags), large2,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, huge0, 0, flags), large2,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, large0, 0, flags), large0,
	    "Unexpected xallocx() behavior");
	/* Test size increase with non-zero extra. */
	assert_zu_lt(xallocx(p, large0, huge0 - large0, flags), huge0,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, large0, 0, flags), large0,
	    "Unexpected xallocx() behavior");
	/* Test size increase with non-zero extra. */
	assert_zu_eq(xallocx(p, large0, large2 - large0, flags), large2,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, large2, 0, flags), large2,
	    "Unexpected xallocx() behavior");
	/* Test size+extra overflow. */
	assert_zu_lt(xallocx(p, large2, hugemax - large2 + 1, flags), huge0,
	    "Unexpected xallocx() behavior");

	dallocx(p, flags);
}