Skip to content
Snippets Groups Projects
Commit f463c44f authored by Tom Lane's avatar Tom Lane
Browse files

Ensure consistent results when FormSortKeys fails to find

all the expected keys (it was returning uninitialized memory).
parent 9b3e2dda
No related branches found
No related tags found
No related merge requests found
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.18 1999/02/13 23:15:27 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.19 1999/06/03 03:17:37 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include <string.h>
#include "executor/executor.h" #include "executor/executor.h"
#include "executor/execdebug.h" #include "executor/execdebug.h"
...@@ -58,6 +59,7 @@ FormSortKeys(Sort *sortnode) ...@@ -58,6 +59,7 @@ FormSortKeys(Sort *sortnode)
if (keycount <= 0) if (keycount <= 0)
elog(ERROR, "FormSortKeys: keycount <= 0"); elog(ERROR, "FormSortKeys: keycount <= 0");
sortkeys = (ScanKey) palloc(keycount * sizeof(ScanKeyData)); 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 * form each scan key from the resdom info in the target list
...@@ -72,7 +74,7 @@ FormSortKeys(Sort *sortnode) ...@@ -72,7 +74,7 @@ FormSortKeys(Sort *sortnode)
reskey = resdom->reskey; reskey = resdom->reskey;
reskeyop = resdom->reskeyop; reskeyop = resdom->reskeyop;
if (reskey > 0) if (reskey > 0) /* ignore TLEs that are not sort keys */
{ {
ScanKeyEntryInitialize(&sortkeys[reskey - 1], ScanKeyEntryInitialize(&sortkeys[reskey - 1],
0, 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment