pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joseph Barillari <jbarilla@princeton.edu>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: More long-string woes
Date: Sun, 05 May 2002 13:47:02 -0400
Message-ID: <15287.1020620822@sss.pgh.pa.us> (raw)
In-Reply-To: <5364.1020578500@sss.pgh.pa.us>
References: <m3g017tyul.fsf@washer.barillari.org>
	<5364.1020578500@sss.pgh.pa.us>

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

inline patch 1: src/pl/plpgsql/src/pl_funcs.c (+7/-2 lines) download inline-1.patch*** 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); }

view thread (3+ messages)

Message-ID: <15287.1020620822@sss.pgh.pa.us>
Permalink:  ../15287.1020620822@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15287.1020620822@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jbarilla@princeton.edu
  Subject: Re: More long-string woes
  In-Reply-To: <15287.1020620822@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox