我试图将我的 char* 参数存储到结构指针的数据成员中。但是当我尝试这样做时,我收到了 Segmentation Fault: 11。
void macro_set(char *name, char *body)
{
verify(body != NULL, "null arg body");
bool nameExists = false;
if(macro_list.name == NULL)
{
macro_list.name = Strdup(name);
macro_list.body = Strdup(body);
}
else
{
struct macro *current = ¯o_list;
for(; current != NULL; current = current->next)
{
if(strcmp(name, current->name) == 0)
{
current->body = Strdup(body);
nameExists = true;
}
}
if(!nameExists)
{
current->name = Strdup(name);
}
}
}
当我尝试将名称存储到 current->name 中时发生错误。感谢任何可以提供帮助的人!