Commit c0e9dc12 authored by Tom Lane's avatar Tom Lane

plpgsql_dstring_append was broken for long strings.

parent 846429e3
......@@ -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.18 2002/05/05 17:38:26 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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment