[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] fixes for apr_vformatter and apr_snprintf

From: Nuutti Kotivuori <naked_at_iki.fi>
Date: 2002-07-11 00:22:48 CEST

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

To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Jul 11 00:23:52 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.