Re: [CODE] do_dig modifications for OasisOLC

From: George Greer (greerga@circlemud.org)
Date: 01/08/01


On Mon, 8 Jan 2001, Ron Martin wrote:

>Please let me know if there are problems with the code.

Yes.

Oh, I suppose you want to know what they are.

>ACMD(do_dig)
>{
>        int iroom = 0, rroom = 0;
>        int dir = 0;

No need to '= 0' the iroom, rroom, or dir.

>        two_arguments(argument, buf, buf2);
>        iroom = atoi(buf2);
>        rroom = real_room(iroom);

You should check for !buf || !buf2 before doing the conversion.

>        if (!buf)
>        {
>                send_to_char("Format: dig <dir> <room number>\r\n", ch);
>                return;
>        }
>        else if (!buf2)
>        {
>                send_to_char("Format: dig <dir> <room number>\r\n", ch);
>                return;
>        }

if (!buf || !buf2)

>                for(i = 0; i < top_of_zone_table; i++) /* Find the zone in table */

; i <= top_of_zone_table;

>                if(i == top_of_zone_table) /* Zone does not exist */

if (i > top_of_zone_table)

>                CREATE(temp_room, struct room_data, 1);
>                memset(temp_room, 0, sizeof(struct room_data)); /* Clear the room
>structure */

CREATE already clears it.

>                temp_room->name = str_dup("An unfinished room"); /* Init stuff */
>                temp_room->description = str_dup("You are in an unfinished room.\r\n");
>                temp_room->number = iroom;
>                temp_room->zone = iroom/100;
>                rroom = add_room(temp_room); /* in oasis.c */

You either need to free() 'temp_room' or allocate it on the stack instead.
OasisOLC makes a copy of all the relevant information.

>        CREATE(world[rroom].dir_option[rev_dir[dir]], struct room_direction_data,1);
>        world[rroom].dir_option[rev_dir[dir]]->general_description = NULL;
>        world[rroom].dir_option[rev_dir[dir]]->keyword = NULL;
>        world[rroom].dir_option[rev_dir[dir]]->to_room = ch->in_room;

You're not checking if you're clobbering an already-existing exit in either
of the allocations.

--
George Greer            | If it's about the CircleMUD mailing list,
greerga@circlemud.org   | mail owner-circle@post.queensu.ca instead.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST