I have the following function:
edge** graph_out_edges(graph* g, int src) {
int i;
int num_edges = 0;
edge** es = (edge**) malloc(sizeof(edge*) * g->num_edges);
for (i = 0; i < g->num_edges; i++) {
if (src == g->edges[i]->src) {
es[num_edges++] = g->edges[i];
}
}
es[num_edges] = NULL;
return es;
}
I add a breakpoint to the function using b graph_out_edges
, run the program using r
, and then continue (c
) twice (I get a segfault if I continue again). I then n
through the function until it moves to the command just after the call to the function
edge** new = graph_out_edges(g, min->dest);
p new[0]
and p new[1]
give valid edges (the members are populated), and p new[2]
gives 0x0
, as expected. I then type r
to restart the program, again continuing twice, but this time I then type ret
(confirming I want to return), type n
to execute the assignment, but now when I type p new[0]
I get
Cannot access memory at address 0x2
(Just for clarity, p new
now says $10 = (edge**) 0x2
)
Any suggestions on why there is this discrepancy between the return value when "n
exting" through the function manually and forcing a return?