From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Joseph Barillari <jbarilla(at)princeton(dot)edu> |
Cc: | pgsql-sql <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: More long-string woes |
Date: | 2002-05-05 17:47:02 |
Message-ID: | 15287.1020620822@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Joseph Barillari <jbarilla(at)princeton(dot)edu> writes:
>> [ problems with long literals in plpgsql ]
> I'm amazed no one has noticed this before. plpgsql_dstring_append
> is broken: it assumes it never needs to more than double the size
> of the string.
I've applied the attached patch to current CVS and the 7.2 branch
(it also works against 7.1 sources). Seems to fix the cases you report.
regards, tom lane
*** src/pl/plpgsql/src/pl_funcs.c.orig Thu Nov 15 18:31:09 2001
--- src/pl/plpgsql/src/pl_funcs.c Sun May 5 13:38:26 2002
***************
*** 64,69 ****
--- 64,70 ----
{
ds->value = palloc(ds->alloc = 512);
ds->used = 0;
+ ds->value[0] = '\0';
}
***************
*** 86,95 ****
plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str)
{
int len = strlen(str);
! if (ds->used + len + 1 > ds->alloc)
{
! ds->alloc *= 2;
ds->value = repalloc(ds->value, ds->alloc);
}
--- 87,100 ----
plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str)
{
int len = strlen(str);
+ int needed = ds->used + len + 1;
! if (needed > ds->alloc)
{
! /* 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);
}
From | Date | Subject | |
---|---|---|---|
Next Message | Gary Stainburn | 2002-05-06 11:41:10 | summary VIEW |
Previous Message | Joel Burton | 2002-05-05 06:19:34 | Re: difficult query |