Skip to content

Commit

Permalink
Fix off-by-one bug and add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wtdcode committed Oct 13, 2024
1 parent 579317b commit fbf34af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/unit/test_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion uc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit fbf34af

Please sign in to comment.