Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
In jsonb_plpython.c, suppress warning message from gcc 10.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 30 Jan 2020 23:25:55 +0000 (18:25 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 30 Jan 2020 23:26:13 +0000 (18:26 -0500)
Very recent gcc complains that PLyObject_ToJsonbValue could return
a pointer to a local variable.  I think it's wrong; but the coding
is fragile enough, and the savings of one palloc() minimal enough,
that it seems better to just do a palloc() all the time.  (My other
idea of tweaking the if-condition doesn't suppress the warning.)

Back-patch to v11 where this code was introduced.

Discussion: https://postgr.es/m/21547.1580170366@sss.pgh.pa.us

contrib/jsonb_plpython/jsonb_plpython.c

index 776cf7c8b9bb180544c3a3c1498488f44f690cd0..8f3389aa7cda1515ac6b05de59b4028d2d4ab4c0 100644 (file)
@@ -413,7 +413,6 @@ PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum)
 static JsonbValue *
 PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_elem)
 {
-   JsonbValue  buf;
    JsonbValue *out;
 
    if (!(PyString_Check(obj) || PyUnicode_Check(obj)))
@@ -424,11 +423,7 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele
            return PLyMapping_ToJsonbValue(obj, jsonb_state);
    }
 
-   /* Allocate JsonbValue in heap only if it is raw scalar value. */
-   if (*jsonb_state)
-       out = &buf;
-   else
-       out = palloc(sizeof(JsonbValue));
+   out = palloc(sizeof(JsonbValue));
 
    if (obj == Py_None)
        out->type = jbvNull;