Clean up some Coverity complaints about commit 0bf3ae88af330496.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 21 Mar 2016 15:59:49 +0000 (11:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 21 Mar 2016 16:00:02 +0000 (12:00 -0400)
The two get_tle_by_resno() calls introduced by this commit lacked any
check for a NULL return, unlike any other calls of that function anywhere
in our tree.  Coverity quite properly complained about it.  Also fix a
misindented line in process_query_params(), which Coverity also complained
about on the grounds that the bad indentation suggested possible programmer
misinterpretation.

contrib/postgres_fdw/deparse.c
contrib/postgres_fdw/postgres_fdw.c

index d1c82597ec368dc7b09e5cede59b0a71471025fc..bdc410d1a35201aff7120167b3066368db4daf45 100644 (file)
@@ -1356,6 +1356,10 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
        int         attnum = lfirst_int(lc);
        TargetEntry *tle = get_tle_by_resno(targetlist, attnum);
 
+       if (!tle)
+           elog(ERROR, "attribute number %d not found in UPDATE targetlist",
+                attnum);
+
        if (!first)
            appendStringInfoString(buf, ", ");
        first = false;
index d6db8340129bfbcd28d5bc72aeda38667d9e8412..9600e3b3c4543effa6b0cf564731c3ec93be0fbc 100644 (file)
@@ -2042,7 +2042,7 @@ postgresRecheckForeignScan(ForeignScanState *node, TupleTableSlot *slot)
  * postgresPlanDirectModify
  *     Consider a direct foreign table modification
  *
- * Decide whether it is safe to modify a foreign table directly,  and if so,
+ * Decide whether it is safe to modify a foreign table directly, and if so,
  * rewrite subplan accordingly.
  */
 static bool
@@ -2119,6 +2119,10 @@ postgresPlanDirectModify(PlannerInfo *root,
 
            tle = get_tle_by_resno(subplan->targetlist, attno);
 
+           if (!tle)
+               elog(ERROR, "attribute number %d not found in subplan targetlist",
+                    attno);
+
            if (!is_foreign_expr(root, baserel, (Expr *) tle->expr))
                return false;
 
@@ -3305,7 +3309,8 @@ process_query_params(ExprContext *econtext,
            param_values[i] = NULL;
        else
            param_values[i] = OutputFunctionCall(&param_flinfo[i], expr_value);
-           i++;
+
+       i++;
    }
 
    reset_transmission_modes(nestlevel);