]> granicus.if.org Git - postgis/commitdiff
Reorganize avprintf a litle.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Mar 2010 20:02:59 +0000 (20:02 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Mar 2010 20:02:59 +0000 (20:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5468 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/stringbuffer.c

index 17ca2171e1ee80c933d6de422f54272b0a580ef1..e9ed5c971112afdb10655cbd5acc89663dd32cb5 100644 (file)
@@ -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;