At 10:10 AM 3/13/02 -0800, Cameron Barry wrote:
Another silly question (thanks Bobby for solving my last one!!)...
I'm getting a Seg Fault in the following code:
if (!IS_NPC(ch))
{
for (i=ch->in_room->track_num; i <= MAX_TRACK_INROOM; i++)
{
if (i == ch->in_room->track_num)
{
ch->in_room->track[i]->name = ch->name; /* <--- THIS LINE */
ch->in_room->track[i]->dir = door;
ch->in_room->track[i]->timer = timer;
if (ch->in_room->track_num >= MAX_TRACK_INROOM)
{
ch->in_room->track_num = 0;
}
else
{
ch->in_room->track_num += 1;
}
}
}
}
According to GDB, ch->in_room->track[i]->name = ch->name; is the line
causing the fault.
I don't really understand -- if both are set to char *, why can't I set one
to the
other? How would I go about accomplishing this? Will I have the same problem
with the integers door and timer?
Assigning strings directly like this is bad.
ch->name = "bubba";
is a no-no
free_string(ch->name);
ch->name = str_dup("bubba");
is much better.