Re: [Code] Strange error.

From: The Fungi (
Date: 01/10/03

On Fri, Jan 10, 2003 at 12:10:37PM -0600, Ronald Fenner wrote:
> sprintf(temp, "\r\n    &c%s list&n\r\n", guild_types[i]);
> strcat(buf, temp);

The method I've been using is:

   len += snprintf(buf + len, sizeof(buf) - len,
    "\r\n    &c%s list&n\r\n", guild_types[i]);

Which will ensure that you never overflow buf so long as you always
keep len == sizeof(buf), might not even be a bad idea to assert()
that if there are general-use functions doing this that you're
afraid your developers might misuse. A friend of mine even suggested
making a struct, maybe called checked_string, that associates an int
for "len" with a fixed-size string.
{ IRL(Jeremy_Stanley); PGP(9E8DFF2E4F5995F8FEADDC5829ABF7441FB84657);
SMTP(; IRC(; ICQ(114362511);
AIM(dreadazathoth); YAHOO(crawlingchaoslabs); FINGER(;
MUD(; WWW(; }

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/26/03 PDT