Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sigsev error on malloc that's driving me nuts

This bit of C code is giving segmentation error in gdb

if ((seq_entry_action=malloc((seq_subphases)*sizeof(int*)))==NULL){
    printf("Cannot allocate memory for seq_entry_action\n");
}

where:

int **seq_entry_action=NULL;
unsigned int seq_subphases=0;

At the time of executing, and If I add a breakpoint in gdb just before this snippet of code (it's just another printf() statement) , the values are

(gdb) p seq_subphases
$3 = 88
(gdb) p seq_entry_action
$4 = (int **) 0x0

then I press next and it segfaults at malloc

I really don't get it.....

like image 365
nass Avatar asked Aug 08 '12 19:08

nass


1 Answers

it was like that indeed... an earlier malloc of wrongly computed sizeof() was the reason this malloc failed.

like image 50
nass Avatar answered Sep 30 '22 09:09

nass