dovecot-2.2: str_*printfa(): Avoid (harder!) growing underlying ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 6 01:05:28 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/5930f7812e28
changeset: 15032:5930f7812e28
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 06 01:04:28 2012 +0300
description:
str_*printfa(): Avoid (harder!) growing underlying buffer if possible.
The previous change for this didn't work properly.

diffstat:

 src/lib/str.c |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (17 lines):

diff -r 9bc2e718392c -r 5930f7812e28 src/lib/str.c
--- a/src/lib/str.c	Tue Sep 04 19:58:59 2012 +0300
+++ b/src/lib/str.c	Thu Sep 06 01:04:28 2012 +0300
@@ -145,10 +145,11 @@
 	init_size += SNPRINTF_INITIAL_EXTRA_SIZE;
 
 	/* @UNSAFE */
-	if (init_size > buffer_get_size(str)) {
+	if (pos+init_size > buffer_get_size(str) &&
+	    pos < buffer_get_size(str)) {
 		/* avoid growing buffer larger if possible. this is also
 		   required if buffer isn't dynamically growing. */
-		init_size = buffer_get_size(str);
+		init_size = buffer_get_size(str)-pos;
 	}
 	tmp = buffer_get_space_unsafe(str, pos, init_size);
 	ret = vsnprintf(tmp, init_size, fmt, args);


More information about the dovecot-cvs mailing list