Ensure consistent results when FormSortKeys fails to find
authorTom Lane <[email protected]>
Thu, 3 Jun 1999 03:17:37 +0000 (03:17 +0000)
committerTom Lane <[email protected]>
Thu, 3 Jun 1999 03:17:37 +0000 (03:17 +0000)
all the expected keys (it was returning uninitialized memory).

src/backend/executor/nodeSort.c

index 5c430b94136f46a207085e5645ecb1b2c439ed93..cd8f1078fd44c981f311350c052923ebc0806139 100644 (file)
@@ -12,6 +12,7 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
+#include <string.h>
 
 #include "executor/executor.h"
 #include "executor/execdebug.h"
@@ -58,6 +59,7 @@ FormSortKeys(Sort *sortnode)
        if (keycount <= 0)
                elog(ERROR, "FormSortKeys: keycount <= 0");
        sortkeys = (ScanKey) palloc(keycount * sizeof(ScanKeyData));
+       MemSet((char *) sortkeys, 0, keycount * sizeof(ScanKeyData));
 
        /* ----------------
         *      form each scan key from the resdom info in the target list
@@ -72,7 +74,7 @@ FormSortKeys(Sort *sortnode)
                reskey = resdom->reskey;
                reskeyop = resdom->reskeyop;
 
-               if (reskey > 0)
+               if (reskey > 0)                 /* ignore TLEs that are not sort keys */
                {
                        ScanKeyEntryInitialize(&sortkeys[reskey - 1],
                                                                   0,