Jim Jagielski wrote: > Nuutti Kotivuori wrote: >> >> * apr_snprintf behaved incorrectly when the output was >> * truncated. It returned the length that was passed in, but that is >> * including the null-terminator. >> > > From the man page for snprintf(): > if the return value is greater than or equal to the size argument, > the string was too short and some of the printed characters were > discarded. > > So if truncated, what is returned *must* be >= the length passed in.
apr_snprintf is not snprintf. >From apr_strings.h: * Note that various standards and implementations disagree on the return * value of snprintf, and side-effects due to %n in the formatting string. * apr_snprintf behaves as follows: * * Process the format string until the entire string is exhausted, or * the buffer fills. If the buffer fills then stop processing immediately * (so no further %n arguments are processed), and return the buffer * length. In all cases the buffer is NUL terminated. * * In no event does apr_snprintf return a negative number. It's not possible * to distinguish between an output which was truncated, and an output which * exactly filled the buffer. If this comment is changed, I can fix try to fix these functions to behave as expected again. -- Naked
