1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-29 22:49:41 +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

@@ -2548,7 +2548,7 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
* in the IntoClause because that's where intorel_startup() can
* conveniently get it from.
*/
stmt->into->viewQuery = copyObject(query);
stmt->into->viewQuery = (Node *) copyObject(query);
}
/* represent the command as a utility Query */

View File

@@ -15599,7 +15599,7 @@ TableFuncTypeName(List *columns)
{
FunctionParameter *p = (FunctionParameter *) linitial(columns);
result = (TypeName *) copyObject(p->argType);
result = copyObject(p->argType);
}
else
result = SystemTypeName("record");

View File

@@ -348,7 +348,7 @@ transformJoinUsingClause(ParseState *pstate,
/* Now create the lvar = rvar join condition */
e = makeSimpleA_Expr(AEXPR_OP, "=",
copyObject(lvar), copyObject(rvar),
(Node *) copyObject(lvar), (Node *) copyObject(rvar),
-1);
/* Prepare to combine into an AND clause, if multiple join columns */

View File

@@ -1255,7 +1255,7 @@ transformAExprIn(ParseState *pstate, A_Expr *a)
/* ROW() op ROW() is handled specially */
cmp = make_row_comparison_op(pstate,
a->name,
(List *) copyObject(((RowExpr *) lexpr)->args),
copyObject(((RowExpr *) lexpr)->args),
((RowExpr *) rexpr)->args,
a->location);
}

View File

@@ -1804,7 +1804,7 @@ addRangeTableEntryForJoin(ParseState *pstate,
rte->joinaliasvars = aliasvars;
rte->alias = alias;
eref = alias ? (Alias *) copyObject(alias) : makeAlias("unnamed_join", NIL);
eref = alias ? copyObject(alias) : makeAlias("unnamed_join", NIL);
numaliases = list_length(eref->colnames);
/* fill in any unspecified alias columns */

View File

@@ -167,7 +167,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
* We must not scribble on the passed-in CreateStmt, so copy it. (This is
* overkill, but easy.)
*/
stmt = (CreateStmt *) copyObject(stmt);
stmt = copyObject(stmt);
/* Set up pstate */
pstate = make_parsestate(NULL);
@@ -2107,7 +2107,7 @@ transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
* We must not scribble on the passed-in IndexStmt, so copy it. (This is
* overkill, but easy.)
*/
stmt = (IndexStmt *) copyObject(stmt);
stmt = copyObject(stmt);
/* Set up pstate */
pstate = make_parsestate(NULL);
@@ -2521,7 +2521,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
* We must not scribble on the passed-in AlterTableStmt, so copy it. (This
* is overkill, but easy.)
*/
stmt = (AlterTableStmt *) copyObject(stmt);
stmt = copyObject(stmt);
/* Caller is responsible for locking the relation */
rel = relation_open(relid, NoLock);