Net is a structure which contain
typedef struct net{
int numele;
struct net **e;
} net;
The following code raises the error:
realloc(): invalid pointer
The realloc is causing problems whenever it is accessed and gives the above error. I don't understand why. If you think there is no problem in this part of the code, let me know because the whole code is 800 line long so i don't think I can post it here.
void add(net *n, net *ne) {
if(n->numele==0) {
n->e = (net **)malloc(sizeof(net *));
n->e[0] = ne;
n->numele = 1;
} else {
n->e = (net **)realloc(n->e, (1 + n->numele)*sizeof(net *));
n->e[n->numele] = ne;
n->numele = n->numele + 1;
}
}
The nets n
and ne
are already initialized somewhere else in the code, so you can assume that they will not be null.