Commit 7c5d57ca authored by Tom Lane's avatar Tom Lane

Fix portability issue in new jsonbsubs code.

On machines where sizeof(Datum) > sizeof(Oid) (that is, any 64-bit
platform), the previous coding would compute a misaligned
workspace->index pointer if nupper is odd.  Architectures where
misaligned access is a hard no-no would then fail.  This appears
to explain why thorntail is unhappy but other buildfarm members
are not.
parent aa6e46da
...@@ -356,7 +356,7 @@ jsonb_subscript_fetch_old(ExprState *state, ...@@ -356,7 +356,7 @@ jsonb_subscript_fetch_old(ExprState *state,
static void static void
jsonb_exec_setup(const SubscriptingRef *sbsref, jsonb_exec_setup(const SubscriptingRef *sbsref,
SubscriptingRefState *sbsrefstate, SubscriptingRefState *sbsrefstate,
SubscriptExecSteps * methods) SubscriptExecSteps *methods)
{ {
JsonbSubWorkspace *workspace; JsonbSubWorkspace *workspace;
ListCell *lc; ListCell *lc;
...@@ -368,9 +368,14 @@ jsonb_exec_setup(const SubscriptingRef *sbsref, ...@@ -368,9 +368,14 @@ jsonb_exec_setup(const SubscriptingRef *sbsref,
nupper * (sizeof(Datum) + sizeof(Oid))); nupper * (sizeof(Datum) + sizeof(Oid)));
workspace->expectArray = false; workspace->expectArray = false;
ptr = ((char *) workspace) + MAXALIGN(sizeof(JsonbSubWorkspace)); ptr = ((char *) workspace) + MAXALIGN(sizeof(JsonbSubWorkspace));
workspace->indexOid = (Oid *) ptr;
ptr += nupper * sizeof(Oid); /*
* This coding assumes sizeof(Datum) >= sizeof(Oid), else we might
* misalign the indexOid pointer
*/
workspace->index = (Datum *) ptr; workspace->index = (Datum *) ptr;
ptr += nupper * sizeof(Datum);
workspace->indexOid = (Oid *) ptr;
sbsrefstate->workspace = workspace; sbsrefstate->workspace = workspace;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment