Fix off-by-one bug and add a unit test

This commit is contained in:
mio 2024-10-13 15:19:05 +08:00
parent ff88348a51
commit a1cbd67ae8
No known key found for this signature in database
GPG Key ID: DFF27E34A47CB873
2 changed files with 5 additions and 1 deletions

View File

@ -181,11 +181,14 @@ static void test_uc_ctl_change_page_size(void)
{
uc_engine *uc;
uc_engine *uc2;
uint32_t pg = 0;
OK(uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc));
OK(uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc2));
OK(uc_ctl_set_page_size(uc, 4096));
OK(uc_ctl_get_page_size(uc, &pg));
TEST_CHECK(pg == 4096);
OK(uc_mem_map(uc2, 1 << 10, 1 << 10, UC_PROT_ALL));
uc_assert_err(UC_ERR_ARG, uc_mem_map(uc, 1 << 10, 1 << 10, UC_PROT_ALL));

3
uc.c
View File

@ -2523,7 +2523,8 @@ uc_err uc_ctl(uc_engine *uc, uc_control_type control, ...)
break;
}
while (page_size) {
// Bits is used to calculate the mask
while (page_size > 1) {
bits++;
page_size >>= 1;
}