[Libclc-developers] cvs/work_in_progress/stl/clc_list.c
Status: Planning
Brought to you by:
augestad
|
From: regis <re...@in...> - 2003-04-05 19:07:49
|
I found the code below in clc_list.c the cvs repository:
<code>
struct clc_list_tag {
struct clc_list_tag *next, *prev;
void* data;
};
clc_list clc_list_new(void)
{
clc_list lst;
lst = calloc(1, sizeof *lst);
return lst;
}
</code>
It is erroneous because though calloc zeroes all the reserved bytes,
it does not mean that the pointers next, prev and data will be NULL:
The representation of a null pointer is not necessarily the
pattern with all bits to zero.
The correct way to init the fields is
clc_list clc_list_new(void)
{
clc_list lst;
lst = malloc(sizeof *lst);
if (! lst) return NULL;
lst->data= NULL;
lst->next= lst->prev= NULL;
return lst;
}
(I can't be contacted till monday...)
--
Regis
|