1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

String: Ensure 'MIN_PAGE_SIZE' is multiple of 'getpagesize'

When 'TEST_LEN' was defined as (4096 * 3) the allocation size Would
not be a multiple of system page size if system page size > 4096.
This commit is contained in:
Noah Goldstein
2022-02-08 15:24:59 -06:00
parent fb55d9b945
commit 02561bb48a
2 changed files with 16 additions and 16 deletions

View File

@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#define TEST_LEN (4096 * 3)
#define TEST_LEN (getpagesize () * 3)
#define MIN_PAGE_SIZE (TEST_LEN + 2 * getpagesize ())
#define TEST_MAIN
@ -393,7 +393,7 @@ int
test_main (void)
{
size_t i, j;
const size_t test_len = MIN(TEST_LEN, 3 * 4096);
test_init ();
check();
check2 ();
@ -435,7 +435,7 @@ test_main (void)
for (j = 0; j < 160; ++j)
{
for (i = 0; i < TEST_LEN;)
for (i = 0; i < test_len;)
{
do_test (getpagesize () - j - 1, 0, i, 127, 0);
do_test (getpagesize () - j - 1, 0, i, 127, 1);
@ -461,17 +461,17 @@ test_main (void)
{
i += 7;
}
else if (i + 161 < TEST_LEN)
else if (i + 161 < test_len)
{
i += 31;
i *= 17;
i /= 16;
if (i + 161 > TEST_LEN)
if (i + 161 > test_len)
{
i = TEST_LEN - 160;
i = test_len - 160;
}
}
else if (i + 32 < TEST_LEN)
else if (i + 32 < test_len)
{
i += 7;
}

View File

@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#define TEST_LEN (4096 * 3)
#define TEST_LEN (getpagesize () * 3)
#define MIN_PAGE_SIZE (TEST_LEN + 2 * getpagesize ())
#define TEST_MAIN
@ -430,7 +430,7 @@ check_overflow (void)
const size_t of_masks[]
= { ULONG_MAX, LONG_MIN, ULONG_MAX - (ULONG_MAX >> 2),
((size_t)LONG_MAX) >> 1 };
const size_t test_len = MIN(TEST_LEN, 3 * 4096);
for (of_idx = 0; of_idx < sizeof (of_masks) / sizeof (of_masks[0]); ++of_idx)
{
of_mask = of_masks[of_idx];
@ -484,7 +484,7 @@ check_overflow (void)
of_mask - j * 2, 0, 127, -1);
}
for (i = 1; i < TEST_LEN; i += i)
for (i = 1; i < test_len; i += i)
{
do_test_n (j, 0, i - 1, of_mask, 0, 127, 0);
do_test_n (j, 0, i - 1, of_mask, 0, 127, 1);
@ -540,7 +540,7 @@ int
test_main (void)
{
size_t i, j;
const size_t test_len = MIN(TEST_LEN, 3 * 4096);
test_init ();
check1 ();
@ -608,7 +608,7 @@ test_main (void)
for (j = 0; j < 160; ++j)
{
for (i = 0; i < TEST_LEN;)
for (i = 0; i < test_len;)
{
do_test_n (getpagesize () - j - 1, 0, i, i + 1, 0, 127, 0);
do_test_n (getpagesize () - j - 1, 0, i, i + 1, 0, 127, 1);
@ -677,17 +677,17 @@ test_main (void)
{
i += 7;
}
else if (i + 161 < TEST_LEN)
else if (i + 161 < test_len)
{
i += 31;
i *= 17;
i /= 16;
if (i + 161 > TEST_LEN)
if (i + 161 > test_len)
{
i = TEST_LEN - 160;
i = test_len - 160;
}
}
else if (i + 32 < TEST_LEN)
else if (i + 32 < test_len)
{
i += 7;
}