aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonb.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2016-02-21 10:30:49 -0500
committerAndrew Dunstan <andrew@dunslane.net>2016-02-21 10:30:49 -0500
commit94c745eb189e2122a3ff86c24443b11408ea2376 (patch)
treece9b310d0b9d5080ca9ed26b41e82739fa762e34 /src/backend/utils/adt/jsonb.c
parent88aca5662d6a6362ce8c5aba08f469e92f44a1e7 (diff)
downloadpostgresql-94c745eb189e2122a3ff86c24443b11408ea2376.tar.gz
postgresql-94c745eb189e2122a3ff86c24443b11408ea2376.zip
Fix two-argument jsonb_object when called with empty arrays
Some over-eager copy-and-pasting on my part resulted in a nonsense result being returned in this case. I have adopted the same pattern for handling this case as is used in the one argument form of the function, i.e. we just skip over the code that adds values to the object. Diagnosis and patch from Michael Paquier, although not quite his solution. Fixes bug #13936. Backpatch to 9.5 where jsonb_object was introduced.
Diffstat (limited to 'src/backend/utils/adt/jsonb.c')
-rw-r--r--src/backend/utils/adt/jsonb.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index 9151a13e3ce..256ef80ecec 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -1455,7 +1455,7 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
errmsg("wrong number of array subscripts")));
if (nkdims == 0)
- PG_RETURN_DATUM(CStringGetTextDatum("{}"));
+ goto close_object;
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
@@ -1509,13 +1509,14 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
(void) pushJsonbValue(&result.parseState, WJB_VALUE, &v);
}
- result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
-
pfree(key_datums);
pfree(key_nulls);
pfree(val_datums);
pfree(val_nulls);
+close_object:
+ result.res = pushJsonbValue(&result.parseState, WJB_END_OBJECT, NULL);
+
PG_RETURN_POINTER(JsonbValueToJsonb(result.res));
}