Skip to content

Commit a7e383d

Browse files
committed
Repair badly broken estimation of output buffer size in lquery_out().
1 parent f758097 commit a7e383d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

contrib/ltree/ltree_io.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,22 +498,21 @@ lquery_out(PG_FUNCTION_ARGS)
498498
*ptr;
499499
int i,
500500
j,
501-
totallen = 0;
501+
totallen = 1;
502502
lquery_level *curqlevel;
503503
lquery_variant *curtlevel;
504504

505505
curqlevel = LQUERY_FIRST(in);
506506
for (i = 0; i < in->numlevel; i++)
507507
{
508+
totallen++;
508509
if (curqlevel->numvar)
509-
totallen = (curqlevel->numvar * 4) + 1 + curqlevel->totallen;
510+
totallen += 1 + (curqlevel->numvar * 4) + curqlevel->totallen;
510511
else
511-
totallen = 2 * 11 + 4;
512-
totallen++;
512+
totallen += 2 * 11 + 4;
513513
curqlevel = LQL_NEXT(curqlevel);
514514
}
515515

516-
517516
ptr = buf = (char *) palloc(totallen);
518517
curqlevel = LQUERY_FIRST(in);
519518
for (i = 0; i < in->numlevel; i++)

0 commit comments

Comments
 (0)