diff options
author | Konstantin Pavlov <thresh@nginx.com> | 2018-11-15 16:23:35 +0300 |
---|---|---|
committer | Konstantin Pavlov <thresh@nginx.com> | 2018-11-15 16:23:35 +0300 |
commit | 6ccba253f8d415337a09fb935606447791ce308c (patch) | |
tree | e0f9a8c5e8ede8cef1500c316d7534dd8de7b972 /src/nxt_mp.c | |
parent | bdde42999b36af85f2f04c0872fdd3e30af52027 (diff) | |
parent | a4b02e17382ccbfc19410c644004c4615b2c2c29 (diff) | |
download | unit-6ccba253f8d415337a09fb935606447791ce308c.tar.gz unit-6ccba253f8d415337a09fb935606447791ce308c.tar.bz2 |
Merged with the default branch.1.6-1
Diffstat (limited to 'src/nxt_mp.c')
-rw-r--r-- | src/nxt_mp.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/nxt_mp.c b/src/nxt_mp.c index a0f19ac2..5c1a4d00 100644 --- a/src/nxt_mp.c +++ b/src/nxt_mp.c @@ -768,7 +768,15 @@ nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2) block1 = (nxt_mp_block_t *) node1; block2 = (nxt_mp_block_t *) node2; - return (uintptr_t) block1->start - (uintptr_t) block2->start; + /* + * Shifting is necessary to prevent overflow of intptr_t when block1->start + * is much greater than block2->start or vice versa. + * + * It is safe to drop one bit since there cannot be adjacent addresses + * because of alignments and allocation sizes. Effectively this reduces + * the absolute values to fit into the magnitude of intptr_t. + */ + return ((uintptr_t) block1->start >> 1) - ((uintptr_t) block2->start >> 1); } |