[pacman-dev] [BUG] alpm_list_remove need an initalized pointer for void **data
Dan McGee
dpmcgee at gmail.com
Thu Aug 7 11:36:55 EDT 2008
On Thu, Aug 7, 2008 at 10:23 AM, solsTiCe d'Hiver
<solstice.dhiver at gmail.com> wrote:
> for me it is a problem with alpm_list_remove but i am not an expert.
>
> look at this
> #include <alpm.h>
>
> int compare_int(const void *a, const void *b) {
> const int* ia = (const int *)a;
> const int* ib = (const int *)b;
> return (*ia > *ib) - (*ia < *ib);
> }
>
> int main(void) {
> alpm_list_t *l=NULL;
> int a=2,a2=2;
> l= alpm_list_add(l, &a);
> l= alpm_list_add(l, &a2);
> void **data=NULL;
> l = alpm_list_remove(l, &a, compare_int, data);
> puts("still ok ?");
> void **data2;
> l = alpm_list_remove(l, &a2, compare_int, data2);
> return 0;
> }
>
> it only seg fault at the second alpm_list_remove
OK, you've found a much better test case here, thanks. This points us
to line 302, the NULL set below:
if(data) {
*data = NULL;
}
This check doesn't seem quite right- shouldn't we be checking *data
for existance before we go setting things? Something like:
if(data && *data) {
*data = NULL;
}
Or what do we do here? Double pointers start confusing me. :)
-Dan
More information about the pacman-dev
mailing list