Commit b1407116 authored by Tom Lane's avatar Tom Lane

Fix ts_stat's failure on empty tsvector.

Also insert a couple of Asserts that check for stack overflow.
Bogus coding appears to be new in 8.4 --- older releases had a much
simpler algorithm here.  Per bug #5111.
parent 201e5b28
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.24 2009/07/16 06:33:44 petere Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.25 2009/10/13 14:33:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -959,17 +959,21 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx, ...@@ -959,17 +959,21 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
node = stat->root; node = stat->root;
/* find leftmost value */ /* find leftmost value */
for (;;) if (node == NULL)
{ stat->stack[stat->stackpos] = NULL;
stat->stack[stat->stackpos] = node; else
if (node->left) for (;;)
{ {
stat->stackpos++; stat->stack[stat->stackpos] = node;
node = node->left; if (node->left)
{
stat->stackpos++;
node = node->left;
}
else
break;
} }
else Assert(stat->stackpos <= stat->maxdepth);
break;
}
tupdesc = CreateTemplateTupleDesc(3, false); tupdesc = CreateTemplateTupleDesc(3, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word", TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
...@@ -1015,6 +1019,7 @@ walkStatEntryTree(TSVectorStat *stat) ...@@ -1015,6 +1019,7 @@ walkStatEntryTree(TSVectorStat *stat)
else else
break; break;
} }
Assert(stat->stackpos <= stat->maxdepth);
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment