]> granicus.if.org Git - postgresql/commitdiff
MAXALIGN the target address where we store flattened value.
authorAmit Kapila <akapila@postgresql.org>
Wed, 3 Oct 2018 03:34:54 +0000 (09:04 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 3 Oct 2018 03:45:03 +0000 (09:15 +0530)
The API (EOH_flatten_into) that flattens the expanded value representation
expects the target address to be maxaligned.  All it's usage adhere to that
principle except when serializing datums for parallel query.  Fix that
usage.

Diagnosed-by: Tom Lane
Author: Tom Lane and Amit Kapila
Backpatch-through: 9.6
Discussion: https://postgr.es/m/11629.1536550032@sss.pgh.pa.us

src/backend/utils/adt/datum.c

index f02a5e77aee427b07c391dc4b3cb18042aad58d3..495768275db57bc7bf13aed0b563d20c8f4e3324 100644 (file)
@@ -338,8 +338,19 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
                }
                else if (eoh)
                {
-                       EOH_flatten_into(eoh, (void *) *start_address, header);
+                       char       *tmp;
+
+                       /*
+                        * EOH_flatten_into expects the target address to be maxaligned,
+                        * so we can't store directly to *start_address.
+                        */
+                       tmp = (char *) palloc(header);
+                       EOH_flatten_into(eoh, (void *) tmp, header);
+                       memcpy(*start_address, tmp, header);
                        *start_address += header;
+
+                       /* be tidy. */
+                       pfree(tmp);
                }
                else
                {