I was trying to solve some compiler warnings, when comming across this function:
int list_rm_element(struct list* l, idx_t idx)
{
if (l == NULL)
return -E_NULL_PTR;
idx_t i = 0;
struct list_node* carriage = l->head;
struct list_node* last;
mutex_lock(&(l->lock));
if (idx == 0)
{
last = l->head;
if (l->head == NULL)
return -E_NULL_PTR;
l->head = last->next;
kfree(last);
l->size --;
mutex_unlock(&l->lock);
return -E_SUCCESS;
}
for (; i == idx && carriage != NULL; carriage = carriage->next)
{
last = carriage;
}
if (carriage == NULL)
{
mutex_unlock(&l->lock);
return -E_NULL_PTR;
}
last->next = carriage->next;
kfree(carriage);
l->size --;
mutex_unlock(&l->lock);
return -E_SUCCESS;
}
From: src/andromeda/lib.c:83
Simple question: Whats the purpose of variable i here and what is supposed to happen when idx != 0 (var last points to a random address?)