1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

Cast result of copyObject() to correct type

copyObject() is declared to return void *, which allows easily assigning
the result independent of the input, but it loses all type checking.

If the compiler supports typeof or something similar, cast the result to
the input type.  This creates a greater amount of type safety.  In some
cases, where the result is assigned to a generic type such as Node * or
Expr *, new casts are now necessary, but in general casts are now
unnecessary in the normal case and indicate that something unusual is
happening.

Reviewed-by: Mark Dilger <hornschnorter@gmail.com>
This commit is contained in:
Peter Eisentraut
2017-03-09 15:18:59 -05:00
parent 66b764341b
commit 4cb824699e
36 changed files with 178 additions and 92 deletions

View File

@ -111,10 +111,10 @@ static Var *search_indexed_tlist_for_var(Var *var,
indexed_tlist *itlist,
Index newvarno,
int rtoffset);
static Var *search_indexed_tlist_for_non_var(Node *node,
static Var *search_indexed_tlist_for_non_var(Expr *node,
indexed_tlist *itlist,
Index newvarno);
static Var *search_indexed_tlist_for_sortgroupref(Node *node,
static Var *search_indexed_tlist_for_sortgroupref(Expr *node,
Index sortgroupref,
indexed_tlist *itlist,
Index newvarno);
@ -1440,7 +1440,7 @@ fix_param_node(PlannerInfo *root, Param *p)
elog(ERROR, "unexpected PARAM_MULTIEXPR ID: %d", p->paramid);
return copyObject(list_nth(params, colno - 1));
}
return copyObject(p);
return (Node *) copyObject(p);
}
/*
@ -1727,7 +1727,7 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
if (tle->ressortgroupref != 0 && !IsA(tle->expr, Var))
{
newexpr = (Node *)
search_indexed_tlist_for_sortgroupref((Node *) tle->expr,
search_indexed_tlist_for_sortgroupref(tle->expr,
tle->ressortgroupref,
subplan_itlist,
OUTER_VAR);
@ -1810,7 +1810,7 @@ convert_combining_aggrefs(Node *node, void *context)
*/
child_agg->args = NIL;
child_agg->aggfilter = NULL;
parent_agg = (Aggref *) copyObject(child_agg);
parent_agg = copyObject(child_agg);
child_agg->args = orig_agg->args;
child_agg->aggfilter = orig_agg->aggfilter;
@ -2054,7 +2054,7 @@ search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist,
* so there's a correctness reason not to call it unless that's set.
*/
static Var *
search_indexed_tlist_for_non_var(Node *node,
search_indexed_tlist_for_non_var(Expr *node,
indexed_tlist *itlist, Index newvarno)
{
TargetEntry *tle;
@ -2095,7 +2095,7 @@ search_indexed_tlist_for_non_var(Node *node,
* And it's also faster than search_indexed_tlist_for_non_var.
*/
static Var *
search_indexed_tlist_for_sortgroupref(Node *node,
search_indexed_tlist_for_sortgroupref(Expr *node,
Index sortgroupref,
indexed_tlist *itlist,
Index newvarno)
@ -2229,7 +2229,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
/* See if the PlaceHolderVar has bubbled up from a lower plan node */
if (context->outer_itlist && context->outer_itlist->has_ph_vars)
{
newvar = search_indexed_tlist_for_non_var((Node *) phv,
newvar = search_indexed_tlist_for_non_var((Expr *) phv,
context->outer_itlist,
OUTER_VAR);
if (newvar)
@ -2237,7 +2237,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
}
if (context->inner_itlist && context->inner_itlist->has_ph_vars)
{
newvar = search_indexed_tlist_for_non_var((Node *) phv,
newvar = search_indexed_tlist_for_non_var((Expr *) phv,
context->inner_itlist,
INNER_VAR);
if (newvar)
@ -2252,7 +2252,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
/* Try matching more complex expressions too, if tlists have any */
if (context->outer_itlist && context->outer_itlist->has_non_vars)
{
newvar = search_indexed_tlist_for_non_var(node,
newvar = search_indexed_tlist_for_non_var((Expr *) node,
context->outer_itlist,
OUTER_VAR);
if (newvar)
@ -2260,7 +2260,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
}
if (context->inner_itlist && context->inner_itlist->has_non_vars)
{
newvar = search_indexed_tlist_for_non_var(node,
newvar = search_indexed_tlist_for_non_var((Expr *) node,
context->inner_itlist,
INNER_VAR);
if (newvar)
@ -2344,7 +2344,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
/* See if the PlaceHolderVar has bubbled up from a lower plan node */
if (context->subplan_itlist->has_ph_vars)
{
newvar = search_indexed_tlist_for_non_var((Node *) phv,
newvar = search_indexed_tlist_for_non_var((Expr *) phv,
context->subplan_itlist,
context->newvarno);
if (newvar)
@ -2380,7 +2380,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
/* Try matching more complex expressions too, if tlist has any */
if (context->subplan_itlist->has_non_vars)
{
newvar = search_indexed_tlist_for_non_var(node,
newvar = search_indexed_tlist_for_non_var((Expr *) node,
context->subplan_itlist,
context->newvarno);
if (newvar)