Skip to content

*: fix overflow in comparator functions used by sorted containers (backport #22498) - #22574

Merged
donaldsharp merged 1 commit into
stable/10.7from
mergify/bp/stable/10.7/pr-22498
Jul 7, 2026
Merged

*: fix overflow in comparator functions used by sorted containers (backport #22498)#22574
donaldsharp merged 1 commit into
stable/10.7from
mergify/bp/stable/10.7/pr-22498

Conversation

@mergify

@mergify mergify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Several comparator functions registered with DECLARE_SKIPLIST_NONUNIQ, DECLARE_RBTREE_UNIQ, and RB_GENERATE use unsigned integer subtraction to produce a comparison result. When the difference between two uint32_t values exceeds INT_MAX, the subtraction wraps around in unsigned arithmetic and the resulting value, when interpreted as a signed int, can have the wrong sign. This causes incorrect ordering in skip-lists and red-black trees.

The fix replaces return a - b with explicit greater-than/less-than comparisons that always produce the correct sign.


This is an automatic backport of pull request #22498 done by Mergify.

Several comparator functions registered with DECLARE_SKIPLIST_NONUNIQ,
DECLARE_RBTREE_UNIQ, and RB_GENERATE use unsigned integer subtraction
to produce a comparison result. When the difference between two uint32_t
values exceeds INT_MAX, the subtraction wraps around in unsigned
arithmetic and the resulting value, when interpreted as a signed int,
can have the wrong sign. This causes incorrect ordering in skip-lists
and red-black trees.

The fix replaces `return a - b` with explicit greater-than/less-than
comparisons that always produce the correct sign.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
(cherry picked from commit f36824e)
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown

Target branch is not in the allowed branches list.

@frrbot frrbot Bot added the bugfix label Jul 6, 2026
@donaldsharp
donaldsharp merged commit a69e75f into stable/10.7 Jul 7, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants