Subject: Re: [bitcoindev] Re: Great Consensus Cleanup Revival

From: Larry Ruane <[email-masked]>
Date: Tue, 2 Jul 2024 18:07:07 -0700 (PDT)

On Monday, July 1, 2024 at 11:03:33 PM UTC-6 Antoine Riard wrote:

Here a snippet example of linked list code checking the pointer 
(`*begin_list`) is non null before the comparison operation to find the 
target element list.

```
pointer_t       ft_list_find(pointer_t **start_list, void *data_ref, int 
(*cmp)())
{
        while (*start_list)
        {
                if (cmp((*start_list)->data, data_ref) == 0)
                        return (*start_list);
                *start_list = (*start_list)->next;
        }
        return (0);
}
```

I assume this function lets you search for an element starting in the 
middle of a single-linked list (the middle because you could call 
`ft_list_find(&p-next, data_ref)` where `p` points to any element in the 
middle of the list, including possibly the last item in the list, in which 
case the loop body wouldn't run). If so, I don't think this does what's 
intended. This actually unlinks (and memory-leaks) elements up to where the 
match is found. I think you want to advance `start_list` this way (I didn't 
test this):

```
    start_list = &(*start_list)->next;
```

Larry

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email-masked].
To view this discussion on the web visit https://groups.google.com/d/msgid/bitcoindev/e2c61ee5-68c4-461e-a132-bb86a4c3e2ccn%40googlegroups.com.