snprintf() not the only way
Posted Feb 5, 2004 21:18 UTC (Thu) by
iabervon (subscriber, #722)
In reply to:
snprintf() not the only way by Ross
Parent article:
snprintf() confusion
To calculate the right buffer size, you should use code which stays tied
to the format and conversion code. Like, for example, "snprintf(NULL, 0,
format, ...)"; the kernel version of vsnprintf actually obeys a zero size
and doesn't dereference the buffer. It would actually be a neat trick to
detect this case and handle it, if possible, at compile time. That way,
people could get the compiler to size their buffers correctly
automatically.
(
Log in to post comments)