Date: Wed, 08 Sep 2010 16:39:06 +0000 From: "Poul-Henning Kamp" <phk@phk.freebsd.dk> To: mdf@FreeBSD.org Cc: freebsd-current@FreeBSD.org Subject: Re: deprecating sprintf(9) Message-ID: <67157.1283963946@critter.freebsd.dk> In-Reply-To: Your message of "Wed, 08 Sep 2010 08:51:57 MST." <AANLkTikO1v7YMFKVZkHZDmurcyfq0QbTkPxG=LNBdKSp@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <AANLkTikO1v7YMFKVZkHZDmurcyfq0QbTkPxG=LNBdKSp@mail.gmail.com>, mdf@
FreeBSD.org writes:
>It seems like a large project, but OTOH sprintf(9) is mighty unsafe in
>the kernel.
Well, it is only unsafe if people used it without knowing what they
are doing, so I think a wholesale automated replacement is both
unwarranted and inadvisable.
I can recommend the following macro for the static buffer cases, it
checks if people know what they are doing with an assert.
#define bprintf(buf, fmt, ...) \
do { \
assert(snprintf(buf, sizeof buf, fmt, __VA_ARGS__) \
< sizeof buf); \
} while (0)
Poul-Henning
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?67157.1283963946>
