ot_vmapper
: Fix range sort comparator logic
#209
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the comparator logic for sorting address ranges as used by the vmapper device.
The current logic uses the difference between the
start
andend
addresses of each range, which are stored asuint32_t
values (which is correct, as virtual address ranges can cover any valid 32 bit address). By subtracting the addresses in unsigned arithmetic we will underflow in the case that the first address is smaller than the second.Furthermore, the conversion to a signed
gint
(int
) means that for large address differences (e.g. consider a region starts at0x00000000
and another at0x80000001
or higher) the result will when cast overflow the 32-bit signed domain to become a negative value.Replace this logic with comparisons that return simple unit sign values. This now performs the intended sorting without risking overflow.