Skip to content

Commit

Permalink
sel4vm, guest_ram: fix compare function
Browse files Browse the repository at this point in the history
The compare function assumed the bb region was smaller than the aa
region, which isn't always true. This commit checks the edge cases.

Signed-off-by: Chris Guikema <[email protected]>
  • Loading branch information
chrisguikema committed Oct 25, 2023
1 parent de8c0ab commit 91f09d9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libsel4vm/src/guest_ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ static int ram_region_cmp(const void *a, const void *b)
{
const vm_ram_region_t *aa = a;
const vm_ram_region_t *bb = b;
return aa->start - bb->start;

if (aa->start == bb->start) {
return 0;
} else if (aa->start < bb->start) {
return -1;
} else {
return 1;
}
}

static void sort_guest_ram_regions(vm_mem_t *guest_memory)
Expand Down

0 comments on commit 91f09d9

Please sign in to comment.