Re: [Code] Strange error.

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

On Sat, Jan 11, 2003 at 03:37:14AM +0100, Thomas Arp wrote:
> Can't this be fixed by changing calls to snprintf to this?
> len += snprintf(MIN(sizeof(buf), buf+len),
>                 MIN(sizeof(buf), sizeof(buf)-len),
>                 "text here");
> It'd be slow like hell, but it wouldn't ever overflow..

Well, if you're going for expensive, you can omit len and MIN()

   snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "format");

But I'm traversing buf twice looking for '\0' so this is probably
not so great an idea. Anyway, sizeof() and MIN() are not really
*that* expensive, comparatively speaking. In fact, I think
sizeof() passed an array[CPP_CONST] gets optimized out entirely, and
MIN() is just a<b?a:b, so it's not that bad an idea comparatively.
{ 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