Re: [GDB] help with output

From: Angus Mezick (angus@EDGIL.CCMAIL.COMPUSERVE.COM)
Date: 01/09/98

     it is even worse then that. if clan is defined as:
     struct clan_struct clan[MAX_CLAN];
     you will be exceeding the array boundry and writing into the date
     right after the the array of clan structs because the array index will
     run from 0 -> (MAX_CLAN-1)
     don't forget, it should be
     sprintf(buf+strlen(buf),"%s Company\r\n",clan[i].clan_name);
     Copying a buffer into itself can do different things on different
     implentations of strings.h on different OS's

     if you don't like strlen, sprintf returns the number of chars copied
     into the buffer.  now if only strcat and strcpy did that :)

______________________________ Forward Header __________________________________
Subject: Re:  [GDB] help with output
Author: at CSERVE
Date:    1/8/98 6:59 PM
     George wrote:
Deja Vu, I just did something like this. :)

>  char buf[MAX_STRING_LENGTH];

You have that right this time.

>  for (i = 1; i < MAX_CLAN; i++) {
>    sprintf(buf, "%s Company\r\n", clan[MAX_CLAN].clan_name);
>  }

What is MAX_CLAN and why are you not using 'i' for your accesses?
The way you have it you'll access the same variable every time, and you
forgot to append the string onto itself.  You'll just keep overwriting the
string until you get to the last one.

>  sprintf(buf, "%sThanxs for useing Company Directorys.\r\nUser %s\r\n",
>        buf, GET_NAME(ch));
>  sprintf(buf, "%sDisconected.....\r\n", buf);

>I'd be greatful if someone could tell me what was going on??

Those errors were really easy to spot, I'm sure a little more work and you
could have found them without trouble.

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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