mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08:00
plpgsql_dstring_append was broken for long strings.
This commit is contained in:
parent
ffd1a5d853
commit
77c4ba63b8
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user