Dear Friends,
I am trying to trace a segfault with valgrind. I get the following message from valgrind:
==3683== Conditional jump or move depends on uninitialised value(s)
==3683== at 0x4C277C5: sparse_mat_mat_kron (sparse.c:165)
==3683== by 0x4C2706E: rec_mating (rec.c:176)
==3683== by 0x401C1C: age_dep_iterate (age_dep.c:287)
==3683== by 0x4014CB: main (age_dep.c:92)
==3683== Uninitialised value was created by a stack allocation
==3683== at 0x401848: age_dep_init_params (age_dep.c:131)
==3683==
==3683== Conditional jump or move depends on uninitialised value(s)
==3683== at 0x4C277C7: sparse_mat_mat_kron (sparse.c:165)
==3683== by 0x4C2706E: rec_mating (rec.c:176)
==3683== by 0x401C1C: age_dep_iterate (age_dep.c:287)
==3683== by 0x4014CB: main (age_dep.c:92)
==3683== Uninitialised value was created by a stack allocation
==3683== at 0x401848: age_dep_init_params (age_dep.c:131)
However, here's the offending line:
/* allocate mating table */
age_dep_data->mtable = malloc (age_dep_data->geno * sizeof (double *));
if (age_dep_data->mtable == NULL)
error (ENOMEM, ENOMEM, nullmsg, __LINE__);
for (int j = 0; j < age_dep_data->geno; j++)
{
131=> age_dep_data->mtable[j] = calloc (age_dep_data->geno, sizeof (double));
if (age_dep_data->mtable[j] == NULL)
error (ENOMEM, ENOMEM, nullmsg, __LINE__);
}
What gives? I thought any call to malloc or calloc allocated heap space; there is no other variable allocated here, right? Is it possible there's another allocation going on (the offending stack allocation) that I'm not seeing?
EDIT: My current suspicion is a stack-allocated array: I declare a pointer to double (stack), then assign to it the result of a function that returns double *. Then I memmove it to a previously allocated place.
I can't memmove, memcpy or assign a stack variable then hope it will persist, can I?