diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-13 14:33:14 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-13 14:33:14 +0000 |
commit | b14071164366e7efee9dc3a017eb7cb4cfac3428 (patch) | |
tree | 7789edc2b908ac9c4650d598967f71917f0f1301 /src/backend/utils/adt/tsvector_op.c | |
parent | 201e5b282bd34379532e9c039e92c88966642951 (diff) | |
download | postgresql-b14071164366e7efee9dc3a017eb7cb4cfac3428.tar.gz postgresql-b14071164366e7efee9dc3a017eb7cb4cfac3428.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/tsvector_op.c')
-rw-r--r-- | src/backend/utils/adt/tsvector_op.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index 6886ee4bcdb..a2848db449a 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -7,7 +7,7 @@ * * * 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, node = stat->root; /* find leftmost value */ - for (;;) - { - stat->stack[stat->stackpos] = node; - if (node->left) + if (node == NULL) + stat->stack[stat->stackpos] = NULL; + else + for (;;) { - stat->stackpos++; - node = node->left; + stat->stack[stat->stackpos] = node; + if (node->left) + { + stat->stackpos++; + node = node->left; + } + else + break; } - else - break; - } + Assert(stat->stackpos <= stat->maxdepth); tupdesc = CreateTemplateTupleDesc(3, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word", @@ -1015,6 +1019,7 @@ walkStatEntryTree(TSVectorStat *stat) else break; } + Assert(stat->stackpos <= stat->maxdepth); } else { |