Correct unsafe use of strcmp(). See rant of same date posted to pghackers.

This commit is contained in:
Tom Lane 2000-07-06 23:03:37 +00:00
parent f0b4ae697f
commit 9f442cbf13
1 changed files with 16 additions and 16 deletions

View File

@ -3,7 +3,7 @@
* out of its tuple * out of its tuple
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.56 2000/07/06 05:48:11 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.57 2000/07/06 23:03:37 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
@ -818,7 +818,8 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
query = (Query *) lfirst(actions); query = (Query *) lfirst(actions);
if (ev_type != '1' || ev_attr >= 0 || !is_instead || strcmp(ev_qual, "<>")) if (ev_type != '1' || ev_attr >= 0 || !is_instead ||
strcmp(ev_qual, "<>") != 0)
{ {
appendStringInfo(buf, "Not a view"); appendStringInfo(buf, "Not a view");
return; return;
@ -929,9 +930,9 @@ get_select_query_def(Query *query, deparse_context *context)
rte = (RangeTblEntry *) lfirst(l); rte = (RangeTblEntry *) lfirst(l);
if (rte->ref == NULL) if (rte->ref == NULL)
continue; continue;
if (!strcmp(rte->ref->relname, "*NEW*")) if (strcmp(rte->ref->relname, "*NEW*") == 0)
continue; continue;
if (!strcmp(rte->ref->relname, "*OLD*")) if (strcmp(rte->ref->relname, "*OLD*") == 0)
continue; continue;
rt_constonly = FALSE; rt_constonly = FALSE;
@ -948,7 +949,7 @@ get_select_query_def(Query *query, deparse_context *context)
sep = " "; sep = " ";
foreach(l, query->targetList) foreach(l, query->targetList)
{ {
bool tell_as = FALSE; bool tell_as = false;
tle = (TargetEntry *) lfirst(l); tle = (TargetEntry *) lfirst(l);
appendStringInfo(buf, sep); appendStringInfo(buf, sep);
@ -959,7 +960,7 @@ get_select_query_def(Query *query, deparse_context *context)
/* Check if we must say AS ... */ /* Check if we must say AS ... */
if (!IsA(tle->expr, Var)) if (!IsA(tle->expr, Var))
tell_as = strcmp(tle->resdom->resname, "?column?"); tell_as = (strcmp(tle->resdom->resname, "?column?") != 0);
else else
{ {
Var *var = (Var *) (tle->expr); Var *var = (Var *) (tle->expr);
@ -967,8 +968,7 @@ get_select_query_def(Query *query, deparse_context *context)
rte = get_rte_for_var(var, context); rte = get_rte_for_var(var, context);
attname = get_attribute_name(rte->relid, var->varattno); attname = get_attribute_name(rte->relid, var->varattno);
if (strcmp(attname, tle->resdom->resname)) tell_as = (strcmp(attname, tle->resdom->resname) != 0);
tell_as = TRUE;
} }
/* and do if so */ /* and do if so */
@ -990,9 +990,9 @@ get_select_query_def(Query *query, deparse_context *context)
if (rte->ref == NULL) if (rte->ref == NULL)
continue; continue;
if (!strcmp(rte->ref->relname, "*NEW*")) if (strcmp(rte->ref->relname, "*NEW*") == 0)
continue; continue;
if (!strcmp(rte->ref->relname, "*OLD*")) if (strcmp(rte->ref->relname, "*OLD*") == 0)
continue; continue;
appendStringInfo(buf, sep); appendStringInfo(buf, sep);
@ -1107,9 +1107,9 @@ get_insert_query_def(Query *query, deparse_context *context)
rte = (RangeTblEntry *) lfirst(l); rte = (RangeTblEntry *) lfirst(l);
if (rte->ref == NULL) if (rte->ref == NULL)
continue; continue;
if (!strcmp(rte->ref->relname, "*NEW*")) if (strcmp(rte->ref->relname, "*NEW*") == 0)
continue; continue;
if (!strcmp(rte->ref->relname, "*OLD*")) if (strcmp(rte->ref->relname, "*OLD*") == 0)
continue; continue;
rt_constonly = FALSE; rt_constonly = FALSE;
@ -1280,9 +1280,9 @@ get_rule_expr(Node *node, deparse_context *context)
if (rte->ref == NULL) if (rte->ref == NULL)
appendStringInfo(buf, "%s.", appendStringInfo(buf, "%s.",
quote_identifier(rte->relname)); quote_identifier(rte->relname));
else if (!strcmp(rte->ref->relname, "*NEW*")) else if (strcmp(rte->ref->relname, "*NEW*") == 0)
appendStringInfo(buf, "new."); appendStringInfo(buf, "new.");
else if (!strcmp(rte->ref->relname, "*OLD*")) else if (strcmp(rte->ref->relname, "*OLD*") == 0)
appendStringInfo(buf, "old."); appendStringInfo(buf, "old.");
else else
appendStringInfo(buf, "%s.", appendStringInfo(buf, "%s.",
@ -1520,14 +1520,14 @@ get_func_expr(Expr *expr, deparse_context *context)
*/ */
if (procStruct->pronargs == 1 && procStruct->proargtypes[0] == InvalidOid) if (procStruct->pronargs == 1 && procStruct->proargtypes[0] == InvalidOid)
{ {
if (!strcmp(proname, "nullvalue")) if (strcmp(proname, "nullvalue") == 0)
{ {
appendStringInfoChar(buf, '('); appendStringInfoChar(buf, '(');
get_rule_expr((Node *) lfirst(expr->args), context); get_rule_expr((Node *) lfirst(expr->args), context);
appendStringInfo(buf, " ISNULL)"); appendStringInfo(buf, " ISNULL)");
return; return;
} }
if (!strcmp(proname, "nonnullvalue")) if (strcmp(proname, "nonnullvalue") == 0)
{ {
appendStringInfoChar(buf, '('); appendStringInfoChar(buf, '(');
get_rule_expr((Node *) lfirst(expr->args), context); get_rule_expr((Node *) lfirst(expr->args), context);