I have an interesting problem with some drunk code I have.
What it does, is slurs a string that is passed to it, depending on the
drunkness of the player. I use it like this:
argument = makedrunk(argument,ch);

Now, argument is, of course, the pointer to the start of the words a player
is speaking in their ch->desc->incomm.

Now, the function basically looks like this:

  char buf[MIL];
  char temp;
  int pos = 0;
  int drunklevel;
  int randomnum;

  /* Check how drunk a person is... */
  if (IS_NPC(ch))
        drunklevel = 0;
  else
        drunklevel = ch->pcdata->condition[COND_DRUNK];

  if (drunklevel > 0)
    {
      do
        {
          temp = toupper(*string);
          if ((temp >= 'A') && (temp <= 'Z'))
            {
              if (drunklevel > drunk[temp - 'A'].min_drunk_level)
                {
                  randomnum = number_range (0, drunk[temp -
'A'].number_of_rep);
                  strcpy (&buf[pos], drunk[temp -
'A'].replacement[randomnum]);
                  pos += strlen (drunk[temp - 'A'].replacement[randomnum]);
                }
              else
                buf[pos++] = *string;
            }
          else
            {
              if ((temp >= '0') && (temp <= '9'))
                {
                  temp = '0' + number_range (0, 9);
                  buf[pos++] = temp;
                }
              else
                buf[pos++] = *string;
            }
        }
      while (*string++);
      buf[pos] = '\0';          /* Mark end of the string... */
      /*strcpy(string, buf);*/
      strncpy(string,buf,MAX_INPUT_LENGTH);
      string[MAX_INPUT_LENGTH-1] = '\0';
      return(string);
    }
  return (string);
}


Now, this has worked perfectly well in my other mud, but when I moved it
over, word for word, to my current one, it doesn't work. What happens is
when the temp = toupper(*string); part is interpreted, it trashes the local
variables for some reason.

(gdb)
2945      if (drunklevel > 0)
(gdb)
2947          do
(gdb)
2949              temp = toupper(*string);
(gdb) print ch
$1 = (CHAR_DATA *) 0xa3db1dc
(gdb) print ch->desc
$2 = (DESCRIPTOR_DATA *) 0xa3d6968
(gdb) print *ch->desc
$3 = {next = 0x0, snoop_by = 0x0, character = 0xa3db1dc, original = 0x0,
  ansi = true, valid = true, host = 0xa3d91c4 "ammaross", descriptor = 5,
  connected = 0, fcommand = true,
  inbuf = "\000ell lala\n\000m drunk 100\n", '\000' <repeats 4072 times>,
  incomm = "yell lala\000mm drunk 100", '\000' <repeats 1001 times>,
  inlast = "yell lala\000mm drunk 100", '\000' <repeats 1001 times>,
  repeat = 0,
  outbuf = 0xa3d91e4 "Exiting
OLC.\n\r\n\r\e[0;36m\e[0;36m[\e[1;37m\e[1;32m1228\
e[0;37m\e[1;30mhp \e[1;37m\e[1;32m1050\e[0;37m\e[1;30mm
\e[1;37m\e[1;32m1300\e[0
;37m\e[1;30mmv\e[0;36m]\e[0;37m \e[0;37m  Violence:  \e[1;33m  4\e[0;37m(
16)
    M"..., outsize = 4096, outtop = 0, run_buf = 0x0, run_head = 0x0,
  showstr_head = 0x0, showstr_point = 0x0, pEdit = 0x0, pString = 0x0,
  editor = 0, page = 0, screenmap = 0x0, oldscreenmap = 0x0}
(gdb) n
2950              if ((temp >= 'A') && (temp <= 'Z'))
(gdb) print ch
$4 = (CHAR_DATA *) 0x4c
(gdb) print ch->desc
Cannot access memory at address 0x80.
(gdb)

Now, why a simple call to toupper would trash a local variable, especially
when it isn't even touched in there is beyond me. I have tried variations on
this, such as sprintf'ing string to a buf, and then using that buf, but same
results.

Any ideas?

Ammaross Danan



Reply via email to