Re: top_of_world

From: Chris Gilbert (chris@buzzbee.freeserve.co.uk)
Date: 12/05/99


Peter Ajamian wrote:
>
> When you define an array as int i[10] you actually end up with 10
> intergers ranging from i[0] to i[9], trying to access i[10] is undefined
> and will usually result in a seg fault or worse.  same thig goes for
> top_of_world, if memory is allocated for top_of_world elements with
> malloc or CREATE those elements are indexed as [0] to [top_of_world
> -1].  trying to index the array with [top_of_world] is undefined and
> will usually result in a seg fault.  See comments dispersed below...

Checking through the src code reveals that top_of_world is actually the
index of the top element, IE if there are 10 rooms it'll have the number
9.  (see do_show and the stats part (line 2029 roughly (using bpl16 with
latest snapshot patch, nothing like being on the bleeding edge :) the
number of rooms is top_of_world+1) or firing up the game in a debugger
and checking the contents of world[top_of_world] should show something
valid.  Unless there was a change of behaviour, I know that top_of_shops
was changed in bpl16 to match the other top_of_x things...

> Andrey Fidrya wrote:
> >
> > Is this a bug?
> > (act.wizard.c):
> > case 6:
> >   strcpy(buf, "Death Traps\r\n-----------\r\n");
> >   for (i = 0, j = 0; i <= top_of_world; i++)
>
> This is a bug ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That's actually correct,  ppl would have hit this a long time ago,
especially as ppl often use efence to link in with the game, to track
memory trashing :)

Chris


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST