From e90cae99afb87f300867856a25952b916b9d73bb Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 29 Mar 2010 20:02:59 +0000 Subject: [PATCH] Reorganize avprintf a litle. git-svn-id: http://svn.osgeo.org/postgis/trunk@5468 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/stringbuffer.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/liblwgeom/stringbuffer.c b/liblwgeom/stringbuffer.c index 17ca2171e..e9ed5c971 100644 --- a/liblwgeom/stringbuffer.c +++ b/liblwgeom/stringbuffer.c @@ -178,23 +178,20 @@ static int stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap) /* Propogate any printing errors upwards (check errno for info) */ if( len < 0 ) return len; - /* If we had enough space, return the number of characters printed */ - if( len < maxlen ) - { - s->str_end += len; - return len; - } - /* We didn't have enough space! Expand the buffer. */ - stringbuffer_makeroom(s, len + 1); - maxlen = (s->capacity - (s->str_end - s->str_start)); + if( len >= maxlen ) + { + stringbuffer_makeroom(s, len + 1); + maxlen = (s->capacity - (s->str_end - s->str_start)); - /* Try to print a second time */ - len = vsnprintf(s->str_end, maxlen, fmt, ap2); + /* Try to print a second time */ + len = vsnprintf(s->str_end, maxlen, fmt, ap2); - /* Printing error or too long still? Error! */ - if( len < 0 ) return len; - if( len >= maxlen ) return -1 + /* Printing error? Error! */ + if( len < 0 ) return len; + /* Too long still? Error! */ + if( len >= maxlen ) return -1 + } /* Move end pointer forward and return. */ s->str_end += len; -- 2.50.1