-
I am also assuming this has an error, as if I try to call this it is what creates the seg fault.. can you please tell me why?
Code:
rule_t* RuleConstruct(rule_t* rule, rule_t* newrule)
{
char** dep = (char**) malloc(sizeof(char*) * rule->depSize);
int h;
for (h = 0; h < rule->depSize; h++){
dep[h] = malloc((strlen(rule->dependency[h]) + 1) * sizeof(char));
strcpy(dep[h], rule->dependency[h]);
}
char** bld = (char**) malloc(sizeof(char*) * rule->bldSize);
int i;
for (i = 0; i < rule->bldSize; i++){
dep[i] = malloc((strlen(rule->buildcmd[i]) + 1) * sizeof(char));
strcpy(dep[i], rule->buildcmd[i]);
}
char* target = (char*) malloc((strlen(rule->target) + 1) * sizeof(char));
strcpy(target, rule->target);
newrule->dependency = dep;
newrule->buildcmd = bld;
newrule->bldSize = rule->bldSize;
newrule->depSize = rule->depSize;
newrule->target = target;
return newrule;
}
-
Have you tried reading the "debug guide" on cpwiki?
http://cpwiki.sourceforge.net/Debugging
A segfault should be easy to detect if you have a debugger at all on the machine (I'm guessing this is Linux, so try doing "gdb myprog", then "run", do the steps to make it crash, and "stack" to see where you ended up).
--
Mats
-
I am planning to use valgrind, but I don't know how so that valgrind can show me the line number in the error
-
Probably because you call it from here:
Code:
for (temp = this->table[hashval]; temp != NULL; temp = temp->next){
if (strcmp(key, temp->rule->target) == 0){
RuleDestruct(rule);
rule_t* newrule;
temp->rule = RuleConstruct(rule, newrule);
return false;
}
And in this code rule is gone, since it was Destructed; but calling Construct without a valid rule in the first parameter leads to bad things.
You'll have to decide what you want to do when you have two rules for the same target, but this ain't it.
-
even when calling the RuleDestruct alone it gives me the seg fault... so I guess I'll have to construct first and then destruct
I should call RuleDestruct(temp->value) instead of RuleDestruct(rule).. fixed that now..