Tom Lane <tgl@sss.pgh.pa.us> writes:
> Joseph Barillari <jbarilla@princeton.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); }