Commit 330cafdf authored by Tom Lane's avatar Tom Lane

Remove no-longer-helpful reliance on fixed-size local array.

Coverity complained about this code, apparently because it uses a local
array of size FUNC_MAX_ARGS without a guard that the input argument list
is no longer than that.  (Not sure why it complained today, since this
code's been the same for a long time; possibly it re-analyzed everything
the List API change touched?)

Rather than add a guard, though, let's just get rid of the local array
altogether.  It was only there to avoid list_nth() calls, and those are
no longer expensive.
parent 90317ab7
...@@ -1734,11 +1734,9 @@ unify_hypothetical_args(ParseState *pstate, ...@@ -1734,11 +1734,9 @@ unify_hypothetical_args(ParseState *pstate,
Oid *actual_arg_types, Oid *actual_arg_types,
Oid *declared_arg_types) Oid *declared_arg_types)
{ {
Node *args[FUNC_MAX_ARGS];
int numDirectArgs, int numDirectArgs,
numNonHypotheticalArgs; numNonHypotheticalArgs;
int i; int hargpos;
ListCell *lc;
numDirectArgs = list_length(fargs) - numAggregatedArgs; numDirectArgs = list_length(fargs) - numAggregatedArgs;
numNonHypotheticalArgs = numDirectArgs - numAggregatedArgs; numNonHypotheticalArgs = numDirectArgs - numAggregatedArgs;
...@@ -1746,25 +1744,20 @@ unify_hypothetical_args(ParseState *pstate, ...@@ -1746,25 +1744,20 @@ unify_hypothetical_args(ParseState *pstate,
if (numNonHypotheticalArgs < 0) if (numNonHypotheticalArgs < 0)
elog(ERROR, "incorrect number of arguments to hypothetical-set aggregate"); elog(ERROR, "incorrect number of arguments to hypothetical-set aggregate");
/* Deconstruct fargs into an array for ease of subscripting */
i = 0;
foreach(lc, fargs)
{
args[i++] = (Node *) lfirst(lc);
}
/* Check each hypothetical arg and corresponding aggregated arg */ /* Check each hypothetical arg and corresponding aggregated arg */
for (i = numNonHypotheticalArgs; i < numDirectArgs; i++) for (hargpos = numNonHypotheticalArgs; hargpos < numDirectArgs; hargpos++)
{ {
int aargpos = numDirectArgs + (i - numNonHypotheticalArgs); int aargpos = numDirectArgs + (hargpos - numNonHypotheticalArgs);
ListCell *harg = list_nth_cell(fargs, hargpos);
ListCell *aarg = list_nth_cell(fargs, aargpos);
Oid commontype; Oid commontype;
/* A mismatch means AggregateCreate didn't check properly ... */ /* A mismatch means AggregateCreate didn't check properly ... */
if (declared_arg_types[i] != declared_arg_types[aargpos]) if (declared_arg_types[hargpos] != declared_arg_types[aargpos])
elog(ERROR, "hypothetical-set aggregate has inconsistent declared argument types"); elog(ERROR, "hypothetical-set aggregate has inconsistent declared argument types");
/* No need to unify if make_fn_arguments will coerce */ /* No need to unify if make_fn_arguments will coerce */
if (declared_arg_types[i] != ANYOID) if (declared_arg_types[hargpos] != ANYOID)
continue; continue;
/* /*
...@@ -1773,7 +1766,7 @@ unify_hypothetical_args(ParseState *pstate, ...@@ -1773,7 +1766,7 @@ unify_hypothetical_args(ParseState *pstate,
* the aggregated values). * the aggregated values).
*/ */
commontype = select_common_type(pstate, commontype = select_common_type(pstate,
list_make2(args[aargpos], args[i]), list_make2(lfirst(aarg), lfirst(harg)),
"WITHIN GROUP", "WITHIN GROUP",
NULL); NULL);
...@@ -1781,30 +1774,23 @@ unify_hypothetical_args(ParseState *pstate, ...@@ -1781,30 +1774,23 @@ unify_hypothetical_args(ParseState *pstate,
* Perform the coercions. We don't need to worry about NamedArgExprs * Perform the coercions. We don't need to worry about NamedArgExprs
* here because they aren't supported with aggregates. * here because they aren't supported with aggregates.
*/ */
args[i] = coerce_type(pstate, lfirst(harg) = coerce_type(pstate,
args[i], (Node *) lfirst(harg),
actual_arg_types[i], actual_arg_types[hargpos],
commontype, -1, commontype, -1,
COERCION_IMPLICIT, COERCION_IMPLICIT,
COERCE_IMPLICIT_CAST, COERCE_IMPLICIT_CAST,
-1); -1);
actual_arg_types[i] = commontype; actual_arg_types[hargpos] = commontype;
args[aargpos] = coerce_type(pstate, lfirst(aarg) = coerce_type(pstate,
args[aargpos], (Node *) lfirst(aarg),
actual_arg_types[aargpos], actual_arg_types[aargpos],
commontype, -1, commontype, -1,
COERCION_IMPLICIT, COERCION_IMPLICIT,
COERCE_IMPLICIT_CAST, COERCE_IMPLICIT_CAST,
-1); -1);
actual_arg_types[aargpos] = commontype; actual_arg_types[aargpos] = commontype;
} }
/* Reconstruct fargs from array */
i = 0;
foreach(lc, fargs)
{
lfirst(lc) = args[i++];
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment