Re: top_of_world

From: Peter Ajamian (pajamian@cheapsam.com)
Date: 12/04/99


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...

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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>     if (ROOM_FLAGGED(i, ROOM_DEATH))
> [...]
> case 7:
>   strcpy(buf, "Godrooms\r\n--------------------------\r\n");
>   for (i = 0, j = 0; i < top_of_world; i++)

This is not ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ should be <=?
>
> There's another one in spec_assign.c:
> void assign_rooms(void)
> {
>   int i;
>
>   ASSIGNROOM(3030, dump);
>   ASSIGNROOM(3031, pet_shops);
>
>   if (dts_are_dumps)
>     for (i = 0; i < top_of_world; i++)

This is not ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>       if (ROOM_FLAGGED(i, ROOM_DEATH))
> world[i].func = dump;
> }
>
> Andrey


     +------------------------------------------------------------+
     | 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