Re: [CODE] More on scribe

From: John Evans (evansj@DATAWEST.NET)
Date: 06/29/98


On Mon, 29 Jun 1998, Chuck wrote:

> Now, after all that trash, my question is what would the rebooting of the
> mud do to the scroll that makes it work?  The code used in do_scribe to
> make the scroll is added below.

Because memory is not being allocated/free'd properly, but when the game
boots, the object is "remade" correctly. (see below)

>         final_scroll = read_object(10097, VIRTUAL); // A blank scroll
>         equip_char(ch, final_scroll, pos);
          ^^^^^^^^^^^^^^^^^^^^^
          I'd move that line to AFTER you get through screwing with the
stats/descrips of the scroll simply for sanity's sake.

>
>         sprintf(buf2, "scroll %s", spells[spellnum]);
>         final_scroll->name = str_dup(buf2);
          ^^^^^^^^^^^^^^^
          Before that line do:
          if (final_scroll->name)
            free(final_scroll->name);

>         final_scroll->description = "A scroll is lying on the ground here.";
          ^^^^^^^^^^^^^^^
          THIS LINE LEADS TO THE CRASH!
          Replace the above line with:

          if (final_scroll->description)
            free(final_scroll->description);
          final_scroll->description =
                   str_dup("A scroll is lying on the ground here.";

>         sprintf(buf2, "a scroll of %s", spells[spellnum]);
>         final_scroll->short_description = str_dup(buf2);
          ^^^^^^^^^^^^^^^
          Before that line do:
          if (final_scroll->short_description)
            free(final_scroll->short_description);


The reason that you free the descriptions (if they exist) before
str_dup'ing them is because str_dup allocates more memory. It's not too
bad, but it's a memory leak and those can cause some strange things in
strange places....

The reason that one section causes the crash is that the obj is extracted
from the game when you quit or recite and that extraction free's the
memory allocated to the object and since the description is there, but not
CREATE'd, the free call crashes the MUD.

Hope that helps.

John Evans <evansj@datawest.net>
http://www.hi-line.net/~evansj/              telnet://spear.gator.net:1066

Any sufficiently advanced technology is indistinguishable from magic.
--Arthur C. Clarke


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



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