Yeah, but for an expanding array, it won't actually matter.
In fact, the preferred way to start and expanding array such as this is
mainTree->branches = NULL;
mainTree->branchCount = 0;
Passing NULL to realloc is the same as calling malloc.
> tree->branches = realloc(tree->branches, brSize*sizeof(BRANCH));
You lose rather badly if realloc fails, you've just lost your pointer to your memory you did have.
Do it like this
Code:
void *temp = realloc(tree->branches, brSize*sizeof(BRANCH));
if ( temp != NULL ) {
tree->branches = temp;
} else {
// some error, continue with existing tree->branches
}
> the realloc as the program doesnt get furthur than this point.
Unfortunately, this is seldom where the problem actually is. The true cause of where the problem is will likely be elsewhere in the code. This is just where the problem is noticed by the memory allocation routines.
Example
Code:
int *p1 = malloc( sizeof *p1 ); // an int
p1[1] = 0; // oops, out of bounds
// but unlikely to cause an immediate failure
// lots more code
int *p2 = malloc( sizeof *p2 ); // this one crashes the machine
// but the damage was caused by overstepping p1