Re: Can't figure out this bug...

From: Robert Moon (
Date: 06/14/00

----- Original Message -----
> From: Allan Grant <pheonix@IQ-CORP.COM>
> It works except for one thing, this guildlist file that it
> generates always has some random symbols
> around the 12th line in the file.  For example:
>               {Aiel Leader} Leara, (Wise One, Taardad)
>       {         {Warder Leader} Lan, (Dai'Shan, Gaidin)

I didn't really go over your code with a fine toothed comb.  However, one
thought that immediately popped into my head is that buf isn't large enough.
You declare buf as buf[MAX_INPUT_LENGTH].  MAX_INPUT_LENGTH is #defined in
structs.h to set the maximum input that would be accepted by the user,
truncating any excess.  Therefore, any function relying upon what the user
inputs, such as do_say, will be safe from memory overruns.  You, however,
arbitrarily used the value of MAX_INPUT_LENGTH in this instance, even though
it has no bearing on what anyone sitting at a terminal will type.
Accordingly, you risk the chance of "the stars aligning" and getting a
rather long player name coupled with a rather long guild name coupled with a
rather long guild title, coupled with a rather long <insert everything else
here>, which results in something larger than MAX_INPUT_LENGTH, hence your
crashes and gobbledygook.

My suggestion?  Well, I have three.  One, you can simply declare buf as
buf[MAX_STRING_LENGTH], which is much larger than MAX_INPUT_LENGTH, if
you're confident that the "worse case scenario" string length won't exceed
that value.  Alternatively, (and I would still do this even if you chose
option one), you can add an overflow check in one of your loops that
contatenate the various elements of the guild list to buf.  Do a grep for
OVERFLOW and see how other routines handled it.  A third alternative (I
wouldn't do it personally) is to set precision specifiers in a sprintf line
that sets the length of each field, possibly truncating the rather long
strings for display purposes.  For instance:
     sprintf(blah_variable, "Name: %.10s, Guild: %.12s, Title:

By the way, did you ever wonder why this line never showed up?
sprintf(buf, "`$                       Current Guild Leaders for All

Take a peek at the very next line.
~-._.-~-`7\r\n", buf);

Good luck,

ICQ:  14598527

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

This archive was generated by hypermail 2b30 : 04/10/01 PDT