[pacman-dev] alpm_list_count gives 1 on an list created by alpm_list_new
hi.
i am just using my free time to code with alpm and alpm_list. nothing to be
published yet (or ever ?)
today i just noticed that
a list created with alpm_list_new has a number of element of 1 as
alpm_list_count reports it:
#include
hi.
i am just using my free time to code with alpm and alpm_list. nothing to be published yet (or ever ?)
today i just noticed that a list created with alpm_list_new has a number of element of 1 as alpm_list_count reports it: #include
#include #include
int main(void) { alpm_list_t *l; l = alpm_list_new(); printf("count=%d\n",alpm_list_count(l)); return(0); }
$ ./test count=1
shining wanted me to post here about that. that's done !
Yes, this is not nice, but needed (we doesn't have alpm_list_node_t or alpm_list_head_t struct): list == NULL is not allowed [otherwise list->data or list->next would lead to a segfault.] Workaround: alpm_list_count could count nodes with not-NULL data pointers only. Btw, this also indicates a more serious bug: as I see, if you remove the only element from a 1-element list, alpm_list_remove() will return with NULL, with is not a valid list pointer... Bye
Yes, this is not nice, but needed (we doesn't have alpm_list_node_t or alpm_list_head_t struct): list == NULL is not allowed [otherwise list->data or list->next would lead to a segfault.] Workaround: alpm_list_count could count nodes with not-NULL data pointers only.
Btw, this also indicates a more serious bug: as I see, if you remove the only element from a 1-element list, alpm_list_remove() will return with NULL, with is not a valid list pointer...
Bye
Correction of myself: since we usually use 'for(i = list; i; i = i->next)', i==NULL is acceptable. So IMHO list = alpm_list_new() <=> list = NULL; would be better; and rename the current alpm_list_new() to _internal_ alpm_list_node_new() [used by alpm_list_add ...]. Then the hackish line 119 could also disappear from alpm_list.c Bye
On Sat, Feb 23, 2008 at 08:36:24PM +0100, Nagy Gabor wrote:
Yes, this is not nice, but needed (we doesn't have alpm_list_node_t or alpm_list_head_t struct): list == NULL is not allowed [otherwise list->data or list->next would lead to a segfault.] Workaround: alpm_list_count could count nodes with not-NULL data pointers only.
Btw, this also indicates a more serious bug: as I see, if you remove the only element from a 1-element list, alpm_list_remove() will return with NULL, with is not a valid list pointer...
Bye
Correction of myself: since we usually use 'for(i = list; i; i = i->next)', i==NULL is acceptable. So IMHO list = alpm_list_new() <=> list = NULL; would be better; and rename the current alpm_list_new() to _internal_ alpm_list_node_new() [used by alpm_list_add ...].
Exactly what I was thinking, but wasn't sure. Thanks.
Then the hackish line 119 could also disappear from alpm_list.c
Hmm, why does renaming a function allows us to do that? Any way you can provide a patch for this? it would be appreciated ;)
From 6d3d84fa38a6d67f441c2b76177a66da72692eec Mon Sep 17 00:00:00 2001
From: Nagy Gabor
participants (3)
-
Nagy Gabor
-
solsTiCe d'Hiver
-
Xavier