From: Liam R. Howlett Date: Thu, 29 Oct 2020 19:11:39 +0000 (-0400) Subject: maple_tree: Fix _mas_store() expand null X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d642d6a6db8b60f76c34465ea70ca8e36df6c006;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix _mas_store() expand null Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index ce4c0d15deb7..b58d84fd2134 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3315,29 +3315,33 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite mas->last = r_max; // if this one is null the next and prev are not. } else { - // Check prev slot if we are overwriting the start. - if (mas->index == r_min && mas->offset && - !slots[mas->offset - 1]) { - mas->offset--; - r_min = mas->index = mas_safe_min(mas, pivots, - mas->offset); - r_max = pivots[mas->offset]; - } - // Check next slot if we are overwriting the end. - if (mas->last == r_max && !slots[mas->offset + 1]) { - mas->last = pivots[mas->offset + 1]; - } - else if (mas->last > r_max) { // expand over this slot if necessary. + if ((mas->last == r_max) && !slots[mas->offset + 1]) { + if (mas->offset < mt_pivots[mt] - 1 && + pivots[mas->offset + 1]) + mas->last = pivots[mas->offset + 1]; + else + mas->last = mas->max; + } else if (mas->last > r_max) { // expand over this slot if necessary. unsigned long piv; + do { piv = _mas_safe_pivot(mas, pivots, ++offset_end, mt); - } while (mas->last > piv); + } while (mas->last >= piv); if (!slots[offset_end]) mas->last = piv; } + + // Check prev slot if we are overwriting the start. + if (mas->index == r_min && mas->offset && + !slots[mas->offset - 1]) { + mas->offset--; + r_min = mas->index = mas_safe_min(mas, pivots, + mas->offset); + r_max = pivots[mas->offset]; + } } }