Fix two places in xml.c that neglected to check the return values of
authorNeil Conway <neilc@samurai.com>
Sat, 12 Jan 2008 10:50:03 +0000 (10:50 +0000)
committerNeil Conway <neilc@samurai.com>
Sat, 12 Jan 2008 10:50:03 +0000 (10:50 +0000)
SPI_prepare() and SPI_cursor_open(), to silence a Coverity warning.

src/backend/utils/adt/xml.c

index 295e826576a7c4b2b93182be3ed17cf7f2a8a960..622d4e05f7ff654c75cdaf6aeb525b2b2a6709fe 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.65 2008/01/12 10:38:32 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.66 2008/01/12 10:50:03 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2137,8 +2137,13 @@ query_to_xmlschema(PG_FUNCTION_ARGS)
    Portal      portal;
 
    SPI_connect();
-   plan = SPI_prepare(query, 0, NULL);
-   portal = SPI_cursor_open(NULL, plan, NULL, NULL, true);
+
+   if ((plan = SPI_prepare(query, 0, NULL)) == NULL)
+       elog(ERROR, "SPI_prepare(\"%s\") failed", query);
+
+   if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, true)) == NULL)
+       elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
+
    result = _SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc,
                                                    InvalidOid, nulls,
                                                    tableforest, targetns));
@@ -2209,8 +2214,13 @@ query_to_xml_and_xmlschema(PG_FUNCTION_ARGS)
    Portal      portal;
 
    SPI_connect();
-   plan = SPI_prepare(query, 0, NULL);
-   portal = SPI_cursor_open(NULL, plan, NULL, NULL, true);
+
+   if ((plan = SPI_prepare(query, 0, NULL)) == NULL)
+       elog(ERROR, "SPI_prepare(\"%s\") failed", query);
+
+   if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, true)) == NULL)
+       elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
+
    xmlschema = _SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc,
                                  InvalidOid, nulls, tableforest, targetns));
    SPI_cursor_close(portal);