Hey Dennis,

Thank you very much for your input. I really don't know more than a
dog about pointers. My C book sucks too, no practical application.
*sigh* And I paid 28 dollars too!

I apologize for not including all the important info -- this was kind of
a continuation from my last post and I assumed (first mistake) that
it would have been clear...

ch->in_room = $1 (struct room-index_data *) 0x404b0970
i = 0
ch->in_room->track[i] = $3 (struct track_data *) 0x0
ch->in_room->track = $4 {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}

Let me elaborate.

In merc.h, I have:

typedef struct track_data    TRACK_DATA;

#define MAX_TRACK_INROOM    6

struct track_data
{
char *    name;
int    door;
int    timer;
};

under room_index_data, I have:

TRACK_DATA   *        track[MAX_TRACK_INROOM];

Now I think the above may be where my problem is -- should
this be w/out a *?    What does the * indicate here? I notice that
if I take it out, I have to call the variables in the track_data structure
with . instead of ->, so I'm assuming the * means that instead of
TRACK_DATA initializing a new array, it also makes it a pointer?
Plah. Fuck if I know.. Anyway, I appreciate your patience, and
your assistance. I will understand this some day.

-Cameron

----- Original Message -----
From: "Dennis" <[EMAIL PROTECTED]>
To: "Cameron Barry" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Wednesday, March 13, 2002 12:46 PM
Subject: Re: Question 2:


> The first step is to understand what the error is.  A SIGSEGV (Segment
> Violation signal) is sent by the OS when your program attempts to access
> memory that it does not have access to.  The way this happens in C is
> when you attempt to use a pointer that points to some memory address
> outside your address space.
>
> GDB told you what line the error was on.  Now you just have to figure out
what
> part of the line created the error.
>
> >          ch->in_room->track[i]->name = ch->name;    /* <--- THIS LINE */
>
> >From here, you should use gdb to track it down further.  "print
ch->name",
> "print ch->in_room", "print i", "print ch->in_room->track[i]" (I suspect
> this one will print out a bogus address), "print
ch->in_room->track[i]->name"
> (I suspect this one will give you an error that gdb can't reference
> the memory).
>
> Doing this will tell you which bogus pointer you are dereferencing.
> >From there you progress to the next step: Figuring out why it's bogus.
>
> My guess: You never set it to anything non-bogus, so by default it ends
> up bogus.
>
> I'm going to go out on a limb here and try to guess what your error is
> without seeing the rest of your code (from what I gather about your
> pointer experience in these 2 emails).  I'm going to guess that in
> struct room_index_data, you still have track declared as
> "TRACK_DATA *    track[7];", and nowhere in your code do you have anything
> even slightly resembling the following:
> for ( i = 0; i < 7; i++ )
> room->track[i] = malloc ( sizeof ( TRACK_DATA ) );
> I'm going to assume that you took Bobby's advice from the last question,
> and did exactly what he suggested, and no more.  That's where the problem
> came in.  His answer only fixed the syntax problem in your code.  It
didn't
> fix the problem with design.  To use that solution, much more is required,
> such as malloc()ing and free()ing the memory in the appropriate places.
>
> For what you are trying to do, Edwin's solution to your previous post
> solves the syntax error, and also fixes the design problem.
>
> Now, there's also the problem with "... = ch->name" that was already
> pointed out in another post.  You'll need to work on that too.
>
> > 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?
>
>
> The char * has nothing to do with your problem.  It's the track[i]->name
> that is causing it.  Since you are doing the same thing with door and
> timer, the same problem will pop up there too.
>
>
> Dennis
>
>
>
> On Wed, 13 Mar 2002, 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?
> >
> > Thanks!
> > -Cameron
> >
> >
> >
>
>
>
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>


Reply via email to