aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonbsubs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-02-01 02:03:59 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-02-01 02:03:59 -0500
commit7c5d57caed4d8af705d0cc3131d0d8ed72b7a41d (patch)
tree6f5500e48085d6bfb1fb3a2995b0bb6cecedf4cd /src/backend/utils/adt/jsonbsubs.c
parentaa6e46daf5304e8d9e66fefc1a5bd77622ec6402 (diff)
downloadpostgresql-7c5d57caed4d8af705d0cc3131d0d8ed72b7a41d.tar.gz
postgresql-7c5d57caed4d8af705d0cc3131d0d8ed72b7a41d.zip
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.
Diffstat (limited to 'src/backend/utils/adt/jsonbsubs.c')
-rw-r--r--src/backend/utils/adt/jsonbsubs.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/backend/utils/adt/jsonbsubs.c b/src/backend/utils/adt/jsonbsubs.c
index 491e27cc04b..cfb923aaa35 100644
--- a/src/backend/utils/adt/jsonbsubs.c
+++ b/src/backend/utils/adt/jsonbsubs.c
@@ -356,7 +356,7 @@ jsonb_subscript_fetch_old(ExprState *state,
static void
jsonb_exec_setup(const SubscriptingRef *sbsref,
SubscriptingRefState *sbsrefstate,
- SubscriptExecSteps * methods)
+ SubscriptExecSteps *methods)
{
JsonbSubWorkspace *workspace;
ListCell *lc;
@@ -368,9 +368,14 @@ jsonb_exec_setup(const SubscriptingRef *sbsref,
nupper * (sizeof(Datum) + sizeof(Oid)));
workspace->expectArray = false;
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;
+ ptr += nupper * sizeof(Datum);
+ workspace->indexOid = (Oid *) ptr;
sbsrefstate->workspace = workspace;