deflist_to_tuplestore dumped core on an option with no value.
authorTom Lane
Tue, 13 Sep 2011 15:36:57 +0000 (11:36 -0400)
committerTom Lane
Tue, 13 Sep 2011 15:36:57 +0000 (11:36 -0400)
Make it return NULL for the option_value, instead.

Per report from Frank van Vugt.  Back-patch to 8.4 where this code was
added.

src/backend/foreign/foreign.c

index 042dbed13d09bd050112b7479b2da382611e716f..a67f70b973d55e13448a6772cc26932200a99873 100644 (file)
@@ -260,7 +260,7 @@ deflist_to_tuplestore(ReturnSetInfo *rsinfo, List *options)
    TupleDesc   tupdesc;
    Tuplestorestate *tupstore;
    Datum       values[2];
-   bool        nulls[2] = {0};
+   bool        nulls[2];
    MemoryContext per_query_ctx;
    MemoryContext oldcontext;
 
@@ -292,7 +292,17 @@ deflist_to_tuplestore(ReturnSetInfo *rsinfo, List *options)
        DefElem    *def = lfirst(cell);
 
        values[0] = CStringGetTextDatum(def->defname);
-       values[1] = CStringGetTextDatum(((Value *) def->arg)->val.str);
+       nulls[0] = false;
+       if (def->arg)
+       {
+           values[1] = CStringGetTextDatum(((Value *) (def->arg))->val.str);
+           nulls[1] = false;
+       }
+       else
+       {
+           values[1] = (Datum) 0;
+           nulls[1] = true;
+       }
        tuplestore_putvalues(tupstore, tupdesc, values, nulls);
    }