Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit330cafd

Browse files
committed
Remove no-longer-helpful reliance on fixed-size local array.
Coverity complained about this code, apparently because it uses a localarray of size FUNC_MAX_ARGS without a guard that the input argument listis no longer than that. (Not sure why it complained today, since thiscode's been the same for a long time; possibly it re-analyzed everythingthe List API change touched?)Rather than add a guard, though, let's just get rid of the local arrayaltogether. It was only there to avoid list_nth() calls, and those areno longer expensive.
1 parent90317ab commit330cafd

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

‎src/backend/parser/parse_func.c

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,37 +1734,30 @@ unify_hypothetical_args(ParseState *pstate,
17341734
Oid*actual_arg_types,
17351735
Oid*declared_arg_types)
17361736
{
1737-
Node*args[FUNC_MAX_ARGS];
17381737
intnumDirectArgs,
17391738
numNonHypotheticalArgs;
1740-
inti;
1741-
ListCell*lc;
1739+
inthargpos;
17421740

17431741
numDirectArgs=list_length(fargs)-numAggregatedArgs;
17441742
numNonHypotheticalArgs=numDirectArgs-numAggregatedArgs;
17451743
/* safety check (should only trigger with a misdeclared agg) */
17461744
if (numNonHypotheticalArgs<0)
17471745
elog(ERROR,"incorrect number of arguments to hypothetical-set aggregate");
17481746

1749-
/* Deconstruct fargs into an array for ease of subscripting */
1750-
i=0;
1751-
foreach(lc,fargs)
1752-
{
1753-
args[i++]= (Node*)lfirst(lc);
1754-
}
1755-
17561747
/* Check each hypothetical arg and corresponding aggregated arg */
1757-
for (i=numNonHypotheticalArgs;i<numDirectArgs;i++)
1748+
for (hargpos=numNonHypotheticalArgs;hargpos<numDirectArgs;hargpos++)
17581749
{
1759-
intaargpos=numDirectArgs+ (i-numNonHypotheticalArgs);
1750+
intaargpos=numDirectArgs+ (hargpos-numNonHypotheticalArgs);
1751+
ListCell*harg=list_nth_cell(fargs,hargpos);
1752+
ListCell*aarg=list_nth_cell(fargs,aargpos);
17601753
Oidcommontype;
17611754

17621755
/* A mismatch means AggregateCreate didn't check properly ... */
1763-
if (declared_arg_types[i]!=declared_arg_types[aargpos])
1756+
if (declared_arg_types[hargpos]!=declared_arg_types[aargpos])
17641757
elog(ERROR,"hypothetical-set aggregate has inconsistent declared argument types");
17651758

17661759
/* No need to unify if make_fn_arguments will coerce */
1767-
if (declared_arg_types[i]!=ANYOID)
1760+
if (declared_arg_types[hargpos]!=ANYOID)
17681761
continue;
17691762

17701763
/*
@@ -1773,38 +1766,31 @@ unify_hypothetical_args(ParseState *pstate,
17731766
* the aggregated values).
17741767
*/
17751768
commontype=select_common_type(pstate,
1776-
list_make2(args[aargpos],args[i]),
1769+
list_make2(lfirst(aarg),lfirst(harg)),
17771770
"WITHIN GROUP",
17781771
NULL);
17791772

17801773
/*
17811774
* Perform the coercions. We don't need to worry about NamedArgExprs
17821775
* here because they aren't supported with aggregates.
17831776
*/
1784-
args[i]=coerce_type(pstate,
1785-
args[i],
1786-
actual_arg_types[i],
1787-
commontype,-1,
1788-
COERCION_IMPLICIT,
1789-
COERCE_IMPLICIT_CAST,
1790-
-1);
1791-
actual_arg_types[i]=commontype;
1792-
args[aargpos]=coerce_type(pstate,
1793-
args[aargpos],
1794-
actual_arg_types[aargpos],
1795-
commontype,-1,
1796-
COERCION_IMPLICIT,
1797-
COERCE_IMPLICIT_CAST,
1798-
-1);
1777+
lfirst(harg)=coerce_type(pstate,
1778+
(Node*)lfirst(harg),
1779+
actual_arg_types[hargpos],
1780+
commontype,-1,
1781+
COERCION_IMPLICIT,
1782+
COERCE_IMPLICIT_CAST,
1783+
-1);
1784+
actual_arg_types[hargpos]=commontype;
1785+
lfirst(aarg)=coerce_type(pstate,
1786+
(Node*)lfirst(aarg),
1787+
actual_arg_types[aargpos],
1788+
commontype,-1,
1789+
COERCION_IMPLICIT,
1790+
COERCE_IMPLICIT_CAST,
1791+
-1);
17991792
actual_arg_types[aargpos]=commontype;
18001793
}
1801-
1802-
/* Reconstruct fargs from array */
1803-
i=0;
1804-
foreach(lc,fargs)
1805-
{
1806-
lfirst(lc)=args[i++];
1807-
}
18081794
}
18091795

18101796

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp