aboutsummaryrefslogtreecommitdiff
path: root/contrib/btree_gist/btree_bit.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist/btree_bit.c')
-rw-r--r--contrib/btree_gist/btree_bit.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index edf75e06842..76297515c5e 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -75,10 +75,14 @@ static bytea *
gbt_bit_xfrm(bytea *leaf)
{
bytea *out = leaf;
- int s = INTALIGN(VARBITBYTES(leaf) + VARHDRSZ);
-
- out = palloc(s);
- SET_VARSIZE(out, s);
+ int sz = VARBITBYTES(leaf) + VARHDRSZ;
+ int padded_sz = INTALIGN(sz);
+
+ out = (bytea *) palloc(padded_sz);
+ /* initialize the padding bytes to zero */
+ while (sz < padded_sz)
+ ((char *) out)[sz++] = 0;
+ SET_VARSIZE(out, padded_sz);
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
return out;
}