snprintf() confusion
This mistake is rarely a problem; snprintf() almost never has to truncate its output, so the return value is what the programmer is expecting. Every miscoded use is an invitation for trouble, however, and really should be fixed. To that end, the 2.6.2-rc3-mm1 tree contains a patch by Juergen Quade which adds a couple of new functions:
int scnprintf(char *buf, size_t size, const char *format, ...);
int vscnprintf(char *buf, size_t size, const char *format, va_list args);
The new functions work the way many programmers expected the old ones to:
they return the length of the string actually created in buf. The
plan is to migrate the kernel over to the new functions; the patch fixes
well over 200 snprintf() and vsnprint() calls. Unless
the old functions are eventually removed, however, they are likely to be a
source of programming errors well into the future.
| Index entries for this article | |
|---|---|
| Kernel | scnprintf() |
