]> granicus.if.org Git - postgresql/commitdiff
Fix ts_stat's failure on empty tsvector.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Oct 2009 14:33:21 +0000 (14:33 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Oct 2009 14:33:21 +0000 (14:33 +0000)
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.

src/backend/utils/adt/tsvector_op.c

index 093f2a348adfb63abfba744c302fc7bb4cd819f7..09fbbc05097cd82de1715e72984b0e986303f52c 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.23 2009/06/11 14:49:04 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.23.2.1 2009/10/13 14:33:21 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
        {