]> granicus.if.org Git - postgresql/commitdiff
Sync addRangeTableEntryForENR() with its peer functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 16 Apr 2017 18:02:47 +0000 (14:02 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 16 Apr 2017 18:02:47 +0000 (14:02 -0400)
addRangeTableEntryForENR had a check for pstate != NULL, which Coverity
pointed out was rather useless since it'd already dereferenced pstate
before that.  More to the point, we'd established policy in commit
bc93ac12c that we'd require non-NULL pstate for all addRangeTableEntryFor*
functions; this test was evidently copied-and-pasted from some older
version of one of those functions.  Make it look more like the others.

In passing, make an elog message look more like the rest of the code,
too.

Michael Paquier

src/backend/parser/parse_relation.c

index f960f3844c9e11424f726a4094ed6371365a33d7..40451f3fef2e4f561df1e8e40db1ce324185f7b8 100644 (file)
@@ -1986,11 +1986,12 @@ addRangeTableEntryForENR(ParseState *pstate,
        RangeTblEntry *rte = makeNode(RangeTblEntry);
        Alias      *alias = rv->alias;
        char       *refname = alias ? alias->aliasname : rv->relname;
-       EphemeralNamedRelationMetadata enrmd =
-         get_visible_ENR(pstate, rv->relname);
+       EphemeralNamedRelationMetadata enrmd;
        TupleDesc       tupdesc;
        int                     attno;
 
+       Assert(pstate != NULL);
+       enrmd = get_visible_ENR(pstate, rv->relname);
        Assert(enrmd != NULL);
 
        switch (enrmd->enrtype)
@@ -2000,7 +2001,7 @@ addRangeTableEntryForENR(ParseState *pstate,
                        break;
 
                default:
-                       elog(ERROR, "unexpected enrtype of %i", enrmd->enrtype);
+                       elog(ERROR, "unexpected enrtype: %d", enrmd->enrtype);
                        return NULL;  /* for fussy compilers */
        }
 
@@ -2056,8 +2057,7 @@ addRangeTableEntryForENR(ParseState *pstate,
         * Add completed RTE to pstate's range table list, but not to join list
         * nor namespace --- caller must do that if appropriate.
         */
-       if (pstate != NULL)
-               pstate->p_rtable = lappend(pstate->p_rtable, rte);
+       pstate->p_rtable = lappend(pstate->p_rtable, rte);
 
        return rte;
 }