Error in do_peep

From: Carlo Mocci (mocci@TIN.IT)
Date: 04/01/98


When doing PEEP on a mob who is carrying some amounts of gold (often two,
three pile of gold, i.e. mob that take objects from the ground), the peep
output is damaged: the description "a big pile of gold" isn't terminated by
the terminator character, causing the MUD to write other parts of strings
in memory.

Strange is, that after you kill the mob, and exam the corpse, everything
becomes ok...

I've looked in act.informative.c -> it lists object as usual in do_peep.
So the problem must be in the function create_money in handler.c or in
money_desc (in handler.c too):

This is the part of create_money that accesses money_desc:

obj->name = str_dup("coins gold");
obj->short_description = str_dup(money_desc(amount));
sprintf(buf, "%s is lying here.", money_desc(amount));
obj->description = str_dup(CAP(buf));

And this is money_desc:

char *money_desc(int amount)
{
  static char buf[128];

  if (amount <= 0) {
    log("SYSERR: Try to create negative or 0 money.");
    return NULL;
  }
  if (amount == 1)
    strcpy(buf, "a gold coin");
  else if (amount <= 10)
    strcpy(buf, "a tiny pile of gold coins");
---- I've cut here, but it is like above ----
  else if (amount <= 1000000)
    strcpy(buf, "an enormous mountain of gold coins");
  else
    strcpy(buf, "an absolutely colossal mountain of gold coins");

  return buf;
}

Questions are: is it correct to strdup a pointer to a string that is freed
when exiting function money_desc -> buf isn't no more allocated when going
up the stack, but also there isn't a reason to overwrite that memory area.

And more important: why the desc isn't working only in do_peep and not also
when examining the corpse ?

Has anyone reported this bug before ? Is this a stock bug, or just a
My-MUD-bug  (we are running an "heavily modified" so I don't know if this
is stock code but I think so)


TIA


Kabir
Coder of DalilaMUD
dalila.shopitaly.net 4000
---------------------------------------------------------------
|        __         __            __  __         __       __  |
|   __  (  )  ___  (  )    __    (  \/  )  __   / _)  __ (  ) |
|  / _) /__\ (  ,)  )(__  /  \    )    (  /  \ ( (_  / _) )(  |
| ( (_ (_)(_) )  \ (____)( () )  (_/\/\_)( () ) \__)( (_ (__) |
|  \__)      (_)\_)       \__/            \__/       \__)     |
|                                                             |
| mailto: mocci@tin.it                                        |
| http://volftp.tin.it/IT/IT/ITALIANI/MOCCI                   |
| http://www.geocities.com/SunsetStrip/Palms/7010             |
---------------------------------------------------------------


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