Skip to content

Commit a1cbd67

Browse files
committed
Fix off-by-one bug and add a unit test
1 parent ff88348 commit a1cbd67

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tests/unit/test_ctl.c

+3
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ static void test_uc_ctl_change_page_size(void)
181181
{
182182
uc_engine *uc;
183183
uc_engine *uc2;
184+
uint32_t pg = 0;
184185

185186
OK(uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc));
186187
OK(uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc2));
187188

188189
OK(uc_ctl_set_page_size(uc, 4096));
190+
OK(uc_ctl_get_page_size(uc, &pg));
191+
TEST_CHECK(pg == 4096);
189192

190193
OK(uc_mem_map(uc2, 1 << 10, 1 << 10, UC_PROT_ALL));
191194
uc_assert_err(UC_ERR_ARG, uc_mem_map(uc, 1 << 10, 1 << 10, UC_PROT_ALL));

uc.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,8 @@ uc_err uc_ctl(uc_engine *uc, uc_control_type control, ...)
25232523
break;
25242524
}
25252525

2526-
while (page_size) {
2526+
// Bits is used to calculate the mask
2527+
while (page_size > 1) {
25272528
bits++;
25282529
page_size >>= 1;
25292530
}

0 commit comments

Comments
 (0)