Re: [Code] Strange error.

From: The Fungi (fungi@yuggoth.org)
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()
completely:

   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(fungi@yuggoth.org); IRC(fungi@irc.yuggoth.org#ccl); ICQ(114362511);
AIM(dreadazathoth); YAHOO(crawlingchaoslabs); FINGER(fungi@yuggoth.org);
MUD(Nergel@srmud.net:2325); WWW(http://fungi.yuggoth.org/); }

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



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