[dovecot] Re: vsnprintf()

Thomas Wouters thomas at xs4all.net
Wed Oct 23 16:36:29 EEST 2002


On Wed, Oct 23, 2002 at 04:16:36PM +0300, Timo Sirainen wrote:
> On Wed, 2002-10-23 at 14:18, Thomas Wouters wrote:
> > I think I stumbled upon a bug in the i_snprintf() function. In the case of
> > vnsprintf() being available, it depends on vnsprintf() returning -1 when the
> > string was longer than the passed-in limit (or it won't terminate the
> > string.). But this isn't the C99-standardized behaviour, and newer glibc's
> > don't do that anymore either, so you can end up with a non-terminated
> > string. This patch should fix it, I think.

> Hm. vsnprintf() does terminate the string with \0 always, unless it
> returns -1. But I'll apply the patch anyway just to be sure :)

Hmm. Yeah, testing confirms you are right, I was just confused by the Linux
manpage on the printf-functions. The FreeBSD manpage states it
unambigiously:

     Snprintf() and vsnprintf() will write at most size-1 of the characters
     printed into the output string (the size'th character then gets the
     terminating `\0')

Hey, that means I can go back and clean up some of my old code :-P

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!



More information about the dovecot mailing list