summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2003-12-17 20:15:41 +0000
committerTom Lane2003-12-17 20:15:41 +0000
commita7e383d241581855cf7b4d6d6defa90444055e90 (patch)
treed98f0f12bd61bd0128842373d36ab2bee73e5981
parentf758097c6de1bc0f288302985377fed49e707958 (diff)
Repair badly broken estimation of output buffer size in lquery_out().
-rw-r--r--contrib/ltree/ltree_io.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c
index 62c033cc5df..99803059f0f 100644
--- a/contrib/ltree/ltree_io.c
+++ b/contrib/ltree/ltree_io.c
@@ -498,22 +498,21 @@ lquery_out(PG_FUNCTION_ARGS)
*ptr;
int i,
j,
- totallen = 0;
+ totallen = 1;
lquery_level *curqlevel;
lquery_variant *curtlevel;
curqlevel = LQUERY_FIRST(in);
for (i = 0; i < in->numlevel; i++)
{
+ totallen++;
if (curqlevel->numvar)
- totallen = (curqlevel->numvar * 4) + 1 + curqlevel->totallen;
+ totallen += 1 + (curqlevel->numvar * 4) + curqlevel->totallen;
else
- totallen = 2 * 11 + 4;
- totallen++;
+ totallen += 2 * 11 + 4;
curqlevel = LQL_NEXT(curqlevel);
}
-
ptr = buf = (char *) palloc(totallen);
curqlevel = LQUERY_FIRST(in);
for (i = 0; i < in->numlevel; i++)