Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 3DB28475931 for ; Sun, 5 May 2002 13:47:10 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 11BAB4758E9 for ; Sun, 5 May 2002 13:47:09 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g45Hl2v15290; Sun, 5 May 2002 13:47:02 -0400 (EDT) To: Joseph Barillari Cc: pgsql-sql Subject: Re: More long-string woes In-reply-to: <5364.1020578500@sss.pgh.pa.us> References: <5364.1020578500@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 05 May 2002 02:01:40 -0400" Date: Sun, 05 May 2002 13:47:02 -0400 Message-ID: <15287.1020620822@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200205/36 X-Sequence-Number: 7672 Tom Lane writes: > Joseph Barillari 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); }