The problem probably occurs because the color() function adds the colour
code characters to the 'string' variable, which is the 'point2' variable
from page_to_char().  point2 is also assigned to use the memory location of
the 'buf' char array.  When the color function is adding the colour codes,
it is probably overflowing the memory that is allocated for it.

To fix the problem you can try making 'buf' a larger array.  I believe that
could do it.  A more robust solution would be to use some sort of dynamic
buffering system.  The latter is what I did for my mud as we were having
similar problems (things like 'mwhere guard' would crash in this same
manner).  We no longer have the problems with displaying large strings....

Hope that help,
Cameron


----- Original Message -----
From: "Keith Mervine" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, April 02, 2002 3:12 PM
Subject: page_to_char (with colour) problem


> Hey folks,
> When page_to_char gets passed a lot of data from another function, I get a
> crash with
> the GDB output looking like this:
>
> #0 0x809153c in colour (type=71, ch=0x5b1b2039, string=0xbfffa432 "") at
> comm.c:3680
>                 3680 if( ch && IS_NPC( ch ) )
>
> (gdb) back
>   #0 0x809153c in colour (type=71, ch=0x5b1b2039, string=0xbfffa432 "") at
> comm.c:3680
>   #1 0x8091c14 in page_to_char (txt=0x38363232 <Address  0x38363232 out of
> bounds>, ch=0x5b1b2039) at comm.c:4035
>   #2 0x6d313b32 in ?? ()
>   Cannot access memory at address 0x335b1b5b
>
>
> Im not that much of a wiz with GDB, can someone give me a hint as to what
> to check next?
>
> It works fine as long as the data I'm adding to the buffer is not alot.
It
> works any other time.
>
> The page_to_char comes from Lopes 2.0 but the colour code is modified and
> listed below.
>
>
> int colour( char type, CHAR_DATA *ch, char *string )
> {
>      char        code[ 20 ];
>      char        *p = '\0';
>
>
> //    if( IS_NPC( ch ) )
>          if( ch  && IS_NPC( ch ) )
>          return( 0 );
>
>      switch( type )
>      {
>          default:
>              strcpy( code, CLR_NORMAL );
>              break;
>          case 'x':
>              strcpy( code, CLR_NORMAL );
>              break;
>          case 'g':
>              strcpy( code, CLR_GREEN );
>              break;
>          case 'o':
>              strcpy( code, CLR_BROWN );
>              break;
>          case 'r':
>              strcpy( code, CLR_RED );
>              break;
>          case 'u':
>              strcpy( code, CLR_BLUE );
>              break;
>          case 'm':
>              strcpy( code, CLR_MAGENTA );
>              break;
>          case 'c':
>              strcpy( code, CLR_CYAN );
>              break;
>          case 'w':
>              strcpy( code, CLR_WHITE );
>              break;
>          case 'G':
>              strcpy( code, CLR_GREEN_BOLD);
>              break;
>          case 'O':
>          case 'y': //high brown oryellow
>              strcpy (code, CLR_YELLOW);
>              break;
>          case 'R':
>              strcpy(code, CLR_RED_BOLD);
>              break;
>          case 'U':
>              strcpy( code, CLR_BLUE_BOLD );
>              break;
>          case 'M':
>              strcpy( code, CLR_MAGENTA_BOLD );
>              break;
>          case 'C':
>              strcpy( code, CLR_CYAN_BOLD );
>              break;
>          case 'W':
>              strcpy( code, CLR_WHITE_BOLD );
>              break;
>          case 'B':
>              strcpy( code, CLR_GREY );
>              break;
>          case 'b':
>              sprintf( code, "%c", '\a' );
>              break;
>          case 'n':
>              strcpy( code, "\n\r" );
>              break;
>          case '@':
>              sprintf( code, "%c", '@' );
>              break;
>      }
>
>      p = code;
>      while( *p != '\0' )
>      {
>          *string = *p++;
>          *++string = '\0';
>      }
>
>      return( strlen( code ) );
> }
>
>
> Any help is appreciated.
>
> Keith (lost in a morass of colour) Mervine
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to