
19 Jul
2002
19 Jul
'02
4:04 p.m.
More snprintf bad news, from the printf() family manual (glibc 2.2.5): These functions return the number of characters printed (not including the trailing `\0' used to end output to strings). snprintf and vsnprintf do not write more than size bytes (including the trailing '\0'), and return -1 if the output was truncated due to this limit. (Thus until glibc 2.0.6. Since glibc 2.1 these functions follow the C99 standard and return the number of characters (exclud ing the trailing '\0') which would have been written to the final string if enough space had been available.) which implies the test for failure should be n = snprintf(s, size, ... if (n < 0 || n >= size)