tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: snprintf(3) behaviour regarding large "n"



On Mon, Sep 29, 2014 at 09:49:18PM +0200, Steffen Nurpmeso wrote:
 > I just looked at OpenBSD now -- they clamp to INT_MAX if >INT_MAX,
 > which is a much more sane approach that i would also have
 > implemented; of course i personally would NEVER implement grazy
 > shit like STD I/O, i have implemented nice context-carrier classes
 > for this problem, which is the only sane approach; and now that
 > i know Plan9 i'm no longer alone with this good stuff :-).  Hmm.
 > (Haha).

Problem with that is that there's a lot of code that checks if the
return value is less than the max size to see if the string (didn't)
get truncated. So if you clamp the max size, this logic breaks.

anyway, this seems like a theoretical problem - are you really
snprintf'ing into a 2GB buffer?

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index