Skip to content

Commit b140711

Browse files
committed
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.
1 parent 201e5b2 commit b140711

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/backend/utils/adt/tsvector_op.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.24 2009/07/16 06:33:44 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.25 2009/10/13 14:33:14 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -959,17 +959,21 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
959959

960960
node = stat->root;
961961
/* find leftmost value */
962-
for (;;)
963-
{
964-
stat->stack[stat->stackpos] = node;
965-
if (node->left)
962+
if (node == NULL)
963+
stat->stack[stat->stackpos] = NULL;
964+
else
965+
for (;;)
966966
{
967-
stat->stackpos++;
968-
node = node->left;
967+
stat->stack[stat->stackpos] = node;
968+
if (node->left)
969+
{
970+
stat->stackpos++;
971+
node = node->left;
972+
}
973+
else
974+
break;
969975
}
970-
else
971-
break;
972-
}
976+
Assert(stat->stackpos <= stat->maxdepth);
973977

974978
tupdesc = CreateTemplateTupleDesc(3, false);
975979
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
@@ -1015,6 +1019,7 @@ walkStatEntryTree(TSVectorStat *stat)
10151019
else
10161020
break;
10171021
}
1022+
Assert(stat->stackpos <= stat->maxdepth);
10181023
}
10191024
else
10201025
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy