according to DDD I'm getting a seg fault from strcpy but I can't quite figure out what I'm doing wrong (still quite new to C). Any help would be greatly appreciated, thanks in advance.
int compare_people(PERSON* first, PERSON* second)
{
char firstName[32];
char secondName[32];
strcpy(firstName, first->name);
strcpy(secondName, second->name);
int returnVal = strcmp(firstName, secondName);
return returnVal;
}
It seems that either first or second is equal to NULL or first->name or second->name is equal to NULL or has non-zero terminated data that due to using strcpy exceeds 32 characters. The other reason can be is that first->name or second->name has invalid pointer for example a pointer to a local data that is already destroyed.
Insert a check in the function. For example
Or you can split this assert in several separate asserts.