commit fbebd71c0ee05f98a54ae7df7065985f58f3ebf6
parent ba2dfcbf03b25bad7e93ecf7448a21f69b24e8b4
Author: Louis Burda <quent.burda@gmail.com>
Date: Thu, 13 Jul 2023 03:06:47 +0200
Fix list_insert_sorted use of offset
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/list.c b/src/list.c
@@ -95,11 +95,14 @@ list_insert_sorted(struct list *list, struct list_link *insert,
bool reverse, list_sort_order_fn in_order, size_t offset, void *user)
{
struct list_link *link;
+ void *link_item, *insert_item;
LIST_ABORT_ON_ARGS(!list || !insert || !in_order);
+ insert_item = ((void *) insert) - offset;
for (LIST_ITER(list, link)) {
- if (in_order(insert, link, user) == !reverse) {
+ link_item = ((void *) link) - offset;
+ if (in_order(insert_item, link_item, user) == !reverse) {
list_link_prepend(link, insert);
return;
}
@@ -120,7 +123,7 @@ list_insert_sorted_bwd(struct list *list, struct list_link *insert,
insert_item = ((void *) insert) - offset;
for (LIST_ITER_BWD(list, link)) {
link_item = ((void *) link) - offset;
- if (in_order(link, insert, user) == !reverse) {
+ if (in_order(link_item, insert_item, user) == !reverse) {
list_link_append(link, insert);
return;
}