]> granicus.if.org Git - postgresql/commitdiff
plpgsql_dstring_append was broken for long strings.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 May 2002 17:38:28 +0000 (17:38 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 May 2002 17:38:28 +0000 (17:38 +0000)
src/pl/plpgsql/src/pl_funcs.c

index 6a503505c4c23535558add8011ae64faa427ac2f..2e0f4d6e7b9f036b815385430f4209d48e2cc884 100644 (file)
@@ -3,7 +3,7 @@
  *                       procedural language
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.17 2001/11/15 23:31:09 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.17.2.1 2002/05/05 17:38:28 tgl Exp $
  *
  *       This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -64,6 +64,7 @@ plpgsql_dstring_init(PLpgSQL_dstring * ds)
 {
        ds->value = palloc(ds->alloc = 512);
        ds->used = 0;
+       ds->value[0] = '\0';
 }
 
 
@@ -86,10 +87,14 @@ void
 plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str)
 {
        int                     len = strlen(str);
+       int                     needed = ds->used + len + 1;
 
-       if (ds->used + len + 1 > ds->alloc)
+       if (needed > ds->alloc)
        {
-               ds->alloc *= 2;
+               /* might have to double more than once, if len is large */
+               do {
+                       ds->alloc *= 2;
+               } while (needed > ds->alloc);
                ds->value = repalloc(ds->value, ds->alloc);
        }